0

I'm trying to pass a parameter into a block but every configuration i do is throwing errors. The parameter im trying to pass in is of type Venue as you can see below.

Here is my perhaps incorrect declaration in the header

-(void)update:(Venue* (^)(NSArray *myScenes, NSError *error))block; 

Here is my implementation which i know is wrong because i cant reference the passed in variable but its the only thing not throwing an error

-(void)update:(Venue* (^)(NSArray *myScenes, NSError *error))block{ //download scenes PFQuery *query = [PFQuery queryWithClassName:@"Scenes"]; [query orderByDescending:@"createdAt"]; [query whereKey:@"venueId" equalTo:venue.objectId]; [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { if (error) { NSLog(@"Error: %@ %@", error, [error userInfo]); } else { // We found messages! scenes = objects; //[PFObject pinAllInBackground:objects]; NSLog(@"Retrieved %lu messages", (unsigned long)[scenes count]); NSLog(@"Venues = %@", scenes); } }]; } 

and heres how im calling it

[_venues[0] update:^Venue *(NSArray *myScenes, NSError *error) { if (error) { NSLog(@"Error: %@ %@", error, [error userInfo]); } else { NSLog(@"myObjects are: %@", myScenes); _venues[0].scenes = myScenes; } }]; 

wrong again. Basically i want to know how to declare this in a way that lets me pass in a variable of type Venue*

1

1 Answer 1

1

The format is as follows:

- (void)someMethodThatTakesABlock:(returnType (^)(parameterTypes))blockName; 

This example is from http://goshdarnblocksyntax.com/

But you're not trying to set the "returnType" of the block, I think that you just want to pass a "Venue*" into the method, and then call the block when your PFQuery finds it's objects?

In which case, you'd need to do something more like this:

- (void)updateVenue:(Venue*)venue completion:(void(^)(NSArray *myScenes, NSError *error))completion{ 

And then inside the method do the following:

[query findObjectsInBackgroundWithBlock:^(NSArray *scenes, NSError *error) { if (error) { NSLog(@"Error: %@ %@", error, [error userInfo]); } else { // We found messages! //[PFObject pinAllInBackground:scenes]; NSLog(@"Retrieved %lu messages", (unsigned long)[scenes count]); NSLog(@"Venues = %@", scenes); } if (completion) completion(scenes, error); }]; 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.