I have the code below which needs to bring out the variable data but i dont know how to do it. Could someone please help. Thanks
class connection {
func connection(){
var userCheck: String = "Fail"
let url = URL(string: "http://192.168.0.24:8080/login")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
let param = ["username": "admin", "password": "admin"]
request.httpBody = try? JSONSerialization.data(withJSONObject: param, options: [])
//Do not delete, testing purposes
//print(String(data: request.httpBody!, encoding: .utf8)!)
let session = URLSession.shared
session.dataTask(with: request) { (data, responce, error) in
//Do not delete, testing purposes
//print(String(data: data!, encoding: .utf8)!)
userCheck = String(data: data!, encoding: .utf8)!
}.resume()
//create return statement
}
}
The above code is the class. However, i need the variable data
returned from
session.dataTask(with: request) { (data, responce, error) in
//Do not delete, testing purposes
//print(String(data: data!, encoding: .utf8)!)
userCheck = String(data: data!, encoding: .utf8)!
}.resume()
//create return statement
I have tried looking at how i can handle a closure statement but cant figure out how to do it in this case. would someone be willing to show me how.