1

When trying to access the GET function from AFHTTPSessionManager from , I get error, inputing the operation:

"Cannot convert value of type '(NSURLSessionDataTask!, AnyObject!) -> Void' to expected argument type '((NSURLSessionDataTask, AnyObject?) -> Void)?'"

    return self.GET("search", parameters: parameters, success: {(operation:NSURLSessionDataTask!, response:AnyObject!) -> Void in
        let dictionaries = response["businesses"] as? [NSDictionary]
        if dictionaries != nil {
            completion(Business.businesses(array: dictionaries!), nil)
            self.appDelegate.businessesLoaded = true
        }
        }, failure: { (operation: AFHTTPSessionManager?, error: NSError!) -> Void in
            completion(nil, error)
    })!

AFHTTPSessionManager.m GET function:

    - (NSURLSessionDataTask *)GET:(NSString *)URLString
                   parameters:(id)parameters
                      success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
                      failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure
    {
        return [self GET:URLString parameters:parameters progress:nil success:success failure:failure];
    }

This all used to work with AFHTTPRequestOperation, which is no longer part of AFNetworking 3 from deprecated NSURLConnection. Hope someone can shed some light on this and thank you very much in advance!

vadian
  • 274,689
  • 30
  • 353
  • 361
  • See the difference between the actual and the expected signature of the closure. Look up the proper signature in the documentation and change the code accordingly. For example the second (`AnyObject`) return type is an implicit unwrapped optional (`!`) but expected is a standard optional (`?`) – vadian Jul 09 '16 at 04:54
  • Thanks for pointing that out, changing to the proper optional did not fix the issues, but I did find my problem being with the super.init of AFNetworking Obj-C classes and trying to use it in a swift class. – user1704986 Jul 14 '16 at 00:46

0 Answers0