我目前正在从https://www.simplifiedios.net/swift-php-mysql-tutorial/修改本教程。该程序的目的是在收到正确的消息时关闭ViewController,如果收到无效的消息则显示UIAltertAction。可能会有一些我错过的东西" notChangingVariable"永远不会改变?
...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...