0
votes

I migrated from AFNetworking 2.5 to 3.0 in Swift and have had an issue with the dataTaskWithRequest method. This method is in a class with superclass of AFHTTPSessionManager. The error I get from XCode is that "Method does not override any method from its superclass".

What's the proper way to instantiate the dataTaskWithRequest method in a SessionManager class?

Other StackOverflow posts have recommended removing the "override" but when I do that, I get the error:

"Method 'dataTaskWithRequest(:completionHandler:)' with Objective-C selector 'dataTaskWithRequest:completionHandler:' conflicts with method 'dataTaskWithRequest(:completionHandler:)' from superclass 'AFURLSessionManager' with the same Objective-C selector"

Code:

class SessionManager: AFHTTPSessionManager {

...
func dataTaskWithRequest(request: NSURLRequest!, completionHandler: ((NSURLResponse?, AnyObject?, NSError?) -> Void)) ->
    NSURLSessionDataTask! {

    if let request = request as? NSMutableURLRequest {
        request.setValue(gQuidsiCache.amznSessionID, forHTTPHeaderField: amazonSesionIDHeader)
        request.setValue(gQuidsiCache.visitorID, forHTTPHeaderField: legacyVisitorIDHeader)
    }

    return super.dataTaskWithRequest(request, completionHandler: completionHandler)
 }


 }
1

1 Answers

0
votes

in Swift 2 this should work:

override func dataTaskWithRequest(request: NSURLRequest, completionHandler: ((NSURLResponse, AnyObject?, NSError?) -> Void)?) -> NSURLSessionDataTask 
{
}