func getSomething(callback: (Array<AnyObject>) -> ()) { var dataTask = NSURLSessionDataTask() dataTask = session.dataTaskWithRequest(request) { (data, response, error) in if (error == nil) { var callbackArray = Array<MyObject>() let responseDict = NSJSONSerialization.JSonObjectWithData(data, options: .MutableContainers, error: nil) as NSDictionary let response = responseDict.objectForKey("response_key") as NSDictionary let array = response.objectForKey("array_key") as NSArray for item: AnyObject in array { var arrayItem = MyObject(dict: item as NSDictionary) callbackArray.append(arrayItem) } callback(callbackArray) } else { // handle an error } } dataTask.resume()}
getSomething() { (response) in if let responseArray = response as? Array<MyObject> { self.somethings = responseArray }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)