Swift not changing variable : <p>I am currently modifying this tutorial from <a href="https://www.simplifiedios.net/swift-php-mysql-tutorial/" rel="nofollow noreferrer">https://www.simplifiedios.net/swift-php-mysql-tutorial/</a> . The purpose of the program is to close a ViewController if the correct message is recieved and to display a UIAltertAction if an invalid message is recieved. Could there be something that i am missing that "notChangingVariable" is never changing?</p>

<pre><code>    ...IBACTION...
    var notChangingVariable: Int

    notChangingVariable = 0
    ...othervariablesdeclared...
    let task = URLSession.shared.dataTask(with: request as URLRequest){
        data, response, error in
        if(error != nil){
            return;
        }

        //parsing the response
        do{
            //converting resonse to NSDictionary
            let myJSON =  try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as? NSDictionary
            //parsing the json
            if let parseJSON = myJSON{
                var msg : String!
                //getting the json response
                msg = parseJSON["message"] as! String?
                if(msg == "SameTeam"){
                    print(msg)
                    notChangingVariable  = 1
                    print(notChangingVariable)
                }
            }
        }catch{
            print("error32 is \(error)")
        }
    }
    task.resume()
    print(notChangingVariable) //IS 0

    ...FURTHER USE notChangingVariable...
</code></pre>
