func postToServerAction() -> String{
var stat = ""
var url: NSURL = NSURL(string: /*External LinK */)!
var request:NSMutableURLRequest = NSMutableURLRequest(URL:url)
var bodyData = "Username=" + userTxt.text + "&Password=" + passwordTxt.text
//var bodyData = "Username=" + userTxt.text
request.HTTPMethod = "POST"
request.HTTPBody = bodyData.dataUsingEncoding(NSUTF8StringEncoding);
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue())
{
(response, data, error) in
var reciveData = NSString(data:data,encoding: NSUTF8StringEncoding)
if(reciveData == "false")
{
stat = "YES"
}else{
stat = "NO"
}
}
return stat
}
Here some Code
I would like to return my variable but there no value inside. may be it is problem on NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()) can anyone tell me how can I manage this func. I would like to return the value from NSURLConnection.sendAsynchronousRequest
in my case there no return value and my variable "reviceData" give me correct value but I still cant assign it to any variable
I'm new for swift and not good in English sorry for the gramma.