jinglei
jinglei

Reputation: 3353

iOS - Incompatible block pointer types in AFNetworking GET method

I'm learning to use AFNetworking and do a GET request.

AFNetworking (3.1.0)

XCode 6

Code:

AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager GET:@"http://localhost:5000/index" parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) {
        NSLog(@"JSON: %@", responseObject);
    } failure:^(NSURLSessionTask *operation, NSError *error) {
        NSLog(@"Error: %@", error)p;
    }];

However, I got the error

Incompatible block pointer types sending 'void (^)(NSURLSessionTask *__strong, NSError *__strong)' to parameter of type 'void (^ __nullable)(NSURLSessionDataTask * __nonnull __strong)'

Tried many times but couldn't figure out why?

Upvotes: 1

Views: 689

Answers (2)

jinglei
jinglei

Reputation: 3353

Finally I find out that the problem really is the wrong version Xcode. In Xcode 6 it doesn't recognize nullable. Upgrading my Xcode just solved the problem.

Upvotes: 2

Iyyappan Ravi
Iyyappan Ravi

Reputation: 3245

i think your parameter value don't send nil values, I am also using afNetworking Get method, please refer below code,

viewDidLoad give below code:

NSURL *url = [NSURL URLWithString:@"http://localhost:5000/index"];

    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    //AFNetworking asynchronous url request
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];

    operation.responseSerializer = [AFJSONResponseSerializer serializer];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {

        movies = [responseObject objectForKey:@"enquiry"];

        NSSortDescriptor *titleSort = [[NSSortDescriptor alloc] initWithKey:@"FirstName"
                                                                  ascending:YES selector:@selector(caseInsensitiveCompare:)];
//        NSMutableArray *sortDescriptors = [[NSMutableArray alloc] initWithObjects: titleSort, nil];
        movies=[NSMutableArray arrayWithArray:[movies sortedArrayUsingDescriptors:@[titleSort]]];

        NSLog(@"The Array: %@",movies);
        [self.mytableView reloadData];

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

        NSLog(@"Request Failed: %@, %@", error, error.userInfo);

    }];

    [operation start];

don't forget #import "AFNetworking.h" in header hope its helpful

Upvotes: 0

Related Questions