I'm trying to write a NSURLSessionDataTask in Swift, and I'm not sure how to, I have this Objective C method, that is doing pretty much exactly what I'm wanting to do in Swift.
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
if (httpResponse.statusCode != 200) return;
NSDictionary *responseDict = [XMLReader dictionaryForXMLData:data options:XMLReaderOptionsProcessNamespaces error:&error];
NSDictionary *body = responseDict[@"Envelope"][@"Body"];
dispatch_async(dispatch_get_main_queue(), ^{
if (block) block(body, nil);
});
}];
I've tried and tried, and I can not figure it out! I hope the community can. This is what my swift code is right now for this section. :)
var session: NSURLSession = NSURLSession.sharedSession()
var task: NSURLSessionDataTask = session.dataTaskWithURL(request, completionHandler: { (<#NSData!#>, <#NSURLResponse!#>, <#NSError!#>) -> Void in
var httpResponse: NSHTTPURLResponse
httpResponse = NSHTTPURLResponse(response: NSHTTPURLResponse)
})
Any ideas? An explanation would be nice, I've tried to read this in the documentation but it's kind of confusing. Also. if this is a double post, please link me! I've tried looking, but couldn't find anything close.