SwiftyJSON
https://github.com/SwiftyJSON/SwiftyJSON looks really promising. However, the instructions only talk about integration with Alamofire
(AFNetworking for Swift). However, due to the nature of the current project, it's already using AFNetworking2
and cannot switch to Alamofire
. However, I'm having trouble integrating AFNetworking
with SwiftyJSON
.
I have the following block of code, how do I convert responseObject
, which can be downcasted to NSDictionary
, to a JSON object as defined in SwiftyJSON
? The code below doesn't work.
let task:NSURLSessionDataTask = AFHTTPSessionManager.GET(
url,
parameters: params,
success: { (task: NSURLSessionDataTask!, responseObject: AnyObject!) in
dispatch_async(dispatch_get_main_queue(), {
// How do I convert responseObject, which can be downcasted to NSDictionary to a JSON object?
let data = JSON(data: responseObject)
completion(task: task, response: data as JSON!, error: nil)
})
},
failure: { (task: NSURLSessionDataTask!, error: NSError!) in
dispatch_async(dispatch_get_main_queue(), {
completion(task: task, response: nil, error: error)
})
}
)