dimanche 1 avril 2018

Variable 'myCellChoice' was never mutated inside if statement in didSelectRowAt indexPath function

I have the function didSelectRowAt indexPath with an if statement inside.

myButtonChoiceString2 successfully passes the String title.text of the button selected from a previous view controller.

When removing the if else statement the code works but am only able then to display back workouts so have included this if else to allow shoulder workouts to be shown.

Please can you see what i am doing wrong with the if else to be getting these warnings:

  • First Warning : Variable 'myCellChoice' was never mutated; consider changing to 'let' constant
  • Second Warning : Initialization of immutable value 'myCellChoice' was never used
  • Third Warning : Initialization of immutable value 'myCellChoice' was never used

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        //First Warning Below
        var myCellChoice = DataService.instance.backWorkouts[indexPath.row]
    
        if myButtonChoiceString2 == "BACK" {
            //Second Warning Below
            let myCellChoice = DataService.instance.backWorkouts[indexPath.row]
        } else if myButtonChoiceString2 == "SHOULDERS" {
            //Third Warning Below
            let myCellChoice = DataService.instance.shoulderWorkouts[indexPath.row]
        }
    
        videoPlayer.loadVideoID(myCellChoice.videoCode)
    }
    
    

Aucun commentaire:

Enregistrer un commentaire