This question already has an answer here:
I need to return the value of dictionary after loading the data from the web service
My code:
func callingWebservice (link:String , POST:String)->[String : AnyObject]{
var shotsDataaaa = [String:AnyObject]()
let request = NSMutableURLRequest(URL: NSURL(string: link)!)
request.HTTPMethod = "POST"
let postString = POST
dispatch_async(dispatch_get_main_queue()) {
request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding)
let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {
(data,response,error) in
do {
shotsDataaaa = try NSJSONSerialization.JSONObjectWithData(data! , options: NSJSONReadingOptions.MutableContainers) as! [String : AnyObject]
print(shotsDataaaa)
}catch{
print("fe sabab tanyyy")
}
}
task.resume()
}
return shotsDataaaa
}
This is the result result
I need to return the data not empty dictionary.
Aucun commentaire:
Enregistrer un commentaire