ios - Converting Swift 2.3 to 3 error: cannot invoke dataTask with an argument list of type -
it project consists of registering user app , registered in mysql database. works in swift 2.3 want in swift 3 , not know how fix it.
error on urlsessions.shared.datatask
code:
else{ let url = url(string: "http://localhost/billpain/secure/register.php")! let request = nsmutableurlrequest(url: url) request.httpmethod = "post" let body = "username=\(usernametxt.text!.lowercased())&password=\(passwordtxt.text!)&email=\(emailtxt.text!)&fullname=\(firstnametxt.text!)%20\(lastnametxt.text!)" request.httpbody = body.data(using: string.encoding.utf8) **urlsession.shared.datatask(with: request, completionhandler: {(data:data?, response:urlresponse?, error:nserror?) in** if error == nil { dispatchqueue.main.async(execute: { { let json = try jsonserialization.jsonobject(with: data!, options: .mutablecontainers) as? nsdictionary guard let parsejson = json else { print ("error while parsing") return } let id = parsejson["id"] if id != nil { print(parsejson) } } catch { print("caught error: \(error)") } }) } else{ print("error: \(error)") } }).resume()
let url = url(string: "http://localhost/billpain/secure/register.php")! var urlrequest = urlrequest(url: url) urlrequest.httpmethod = "post" let body = "username=\(usernametxt.text!.lowercased())&password=\(passwordtxt.text!)&email=\(emailtxt.text!)&fullname=\(firstnametxt.text!)%20\(lastnametxt.text!)" urlrequest.httpbody = body.data(using: string.encoding.utf8) let task = urlsession.shared.datatask(with: urlrequest) { (data, response, error) in if let error = error { print("error:", error) return } { guard let data = data else { return } guard let json = try jsonserialization.jsonobject(with: data, options: []) as? [string: anyobject] else { return } print("json:", json) } catch { print("error:", error) } }task.resume()
Comments
Post a Comment