Why does this JSON code not work in Swift 3.2 -
i on final leg of first part of app. have been following tutorial exactly, every single article find has achient code. anyway, am, , receiving 2 errors have never seen before.
these erors: 1. use of unresolved identifer mutablecontainers 2. argument in call
any appreciated. have changed url names privacy.
// send user data server side let myurl = nsurl(string: "https://www.nyserver.com/userregister.php"); let request = nsmutableurlrequest(url:myurl! url); request.httpmethod = "post"; let poststring = "email=\(string(describing: useremail))&password=\(string(describing: userpassword))"; request.httpbody = poststring.data(using: string.encoding.utf8); let task = urlsession.shared.datatask(with: request urlrequest) { data, response, error in if error != nil { print("error=\(string(describing: error))") return } var err: nserror? var json = jsonserialization.jsonobjectwithdata(data, options: .mutablecontainers, &error) as? nsdictionary if let parsejson = json { var resultvalue = parsejson["status"] as? string print("result: \(resultvalue)") var isuserregistered:bool = false; if(resultvalue=="sucess") { isuserregistered = true; } var messagetodisplay:string = parsejson["message"] string!; if(!isuserregistered) { messagetodisplay = parsejson["message"] string!; } dispatchqueue.main.async(execute: { //display alert messagewith confirmation. var myalert = uialertcontroller(title:"alert", message:messagetodisplay, preferredstyle: uialertcontrollerstyle.alert); let okaction = uialertaction(title:"ok", style:uialertactionstyle.default){ action in self.dismiss(animated: true, completion:nil); } myalert.addaction(okaction); self.present(myalert, animated:true, completion:nil); }); } } task.resume()
Comments
Post a Comment