I am creating a swift class which contain of a function which validate if the user is true. However, the userVerifyResult
will always return \"false\" even if t
Use completion handler, as Apple does in their frameworks:
func verifyUser(completionHandler: ((result: Bool)->())) {
then return the result via
if(json["valid"]! == "true"){
completionHandler(result: true)
}else{
completionHandler(result: false)
}
then invoke it as
verifyUser { (result) -> () in
println(result)
}
There is no way to block a NSURLSessionDataTask
(that i know of) until you return the function, so its not possible to do it like that. You will have to have a callback in your tasks completion handler that will print the result or delegate the printing to another function