In the current code, which I don’t have, it seems to return nothing, I can’t find out what causes the problem.
func getQuests(category: NSString, count: Int) -> NSArray {
var quests = NSArray()
Alamofire.request(.GET, apiUrlString, parameters: ["category": category, "count": count])
.responseJSON { (request, response, json, error) in
dispatch_async(dispatch_get_main_queue(), {
quests = json as NSArray
})
}
println(quests) #=> ()
return quests
}
Does anyone know how to solve the problem I have?
[Refresh] . This is the status.
Look at the fifth and eighth lines. I can’t get the quest quest.
var quests = NSArray()
getQuests("normal", count: 30, completionHandler: {
quests in
self.quests = quests
})
println(self.quests) #=> ()
func getQuests(category: NSString, count: Int, completionHandler: (NSArray -> Void)) {
var quests = NSArray()
Alamofire.request(.GET, apiUrlString, parameters: ["category": category, "count": count])
.responseJSON { (request, response, json, error) in
dispatch_async(dispatch_get_main_queue(), {
quests = json as NSArray
completionHandler(quests)
})
}
}
Thank.
source
share