简体   繁体   中英

Completion block return type not recognized

Im making my first completion block and for some reason its not recognizing the return type so I cant pass the value back to the method call.

Heres my header declaration

+(void)downloadVenues:(void (^)(NSArray *myVenues, NSError *error))block;

Heres my implementation

+(void)downloadVenues:(void (^)(NSArray *myVenues, NSError *error))block{


//download scenes
PFQuery *query = [PFQuery queryWithClassName:@"Venues"];
[query orderByDescending:@"createdAt"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (error) {
        NSLog(@"Error: %@ %@", error, [error userInfo]);
    }
    else {
        // We found messages!
        myVenues = objects;


        NSLog(@"Retrieved %lu messages", (unsigned long)[myVenues count]);




    }
}];

And heres calling it in another file

//download venues
[Venue downloadVenues:^(NSArray *myVenues, NSError *error){
    if (error) {
        NSLog(@"Error: %@ %@", error, [error userInfo]);
    }
    else {

    NSLog(@"myObjects are: %@", myVenues);
    _venues = myVenues;

    [self loadAnnotations];

    }
}];

For some reason its not recognizing myVenues in the implementation. Why and how do i fix this? Thanks

Your implementation is never calling the completion block. Here's what you should do:

+(void)downloadVenues:(void (^)(NSArray *myVenues, NSError *error))block{


//download scenes
PFQuery *query = [PFQuery queryWithClassName:@"Venues"];
[query orderByDescending:@"createdAt"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (error) {
        NSLog(@"Error: %@ %@", error, [error userInfo]);
        block(nil, error);
    }
    else {
        // We found messages!
        block(objects, nil);


        NSLog(@"Retrieved %lu messages", (unsigned long)[myVenues count]);




    }
}];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM