Search code examples
iosobjective-cswiftafnetworkingafnetworking-2

Swift error : '(AFHTTPRequestOperation! , NSError? ) -> is not convertible to '((AFHTTPRequestOperation? , NSError) -> Void?


I am using AFNetworking in swift and i am facing a problem in converting following code to swift

Objective C

[client GET:url parameters:nil success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {

} failure:^(AFHTTPRequestOperation * _Nullable operation, NSError * _Nonnull error) {

}];

Swift Code (gives error)

self.client.GET(url,
        parameters: nil,
        success: { (operation: AFHTTPRequestOperation!, responseObject: AnyObject!) in

        },
        failure: { (operation: AFHTTPRequestOperation!, error: NSError!) in

    })

Solution

  • This should work:

    self.client.GET(url, parameters: nil, success: { (operation: AFHTTPRequestOperation, responseObject: AnyObject?) in
    
    }, failure: { (operation: AFHTTPRequestOperation?, error: NSError) in
    
    })