1

I have function, where I add block variable blockIfLoadingImageFromServer to array:

- (UIImage *)getImageWithblockIfLoadingImageFromServer:(void (^)(UIImage *imageCompleted))blockIfLoadingImageFromServer
{
      [array addObject:blockIfLoadingImageFromServer];
}

Then I want to get this variable, but I don't know how. I tried:

(void (^)(UIImage *imageCompleted))blockIfLoadingImageFromServer = [array objectAtIndex:0];
void (^)(UIImage *imageCompleted) *blockIfLoadingImageFromServer = [array objectAtIndex:0];

But that gives an error (bad syntax). How can I do this?

1 Answer 1

3

I usually typedef to make my life easier:

typedef void (^ImageBlock)(UIImage*);

And then:

- (void) doSomethingWithBlock: (ImageBlock) block
{
    [array addObject:[block copy]];
}

- (void) doSomethingElse
{
    ImageBlock block = [array lastObject];
    …
}
Sign up to request clarification or add additional context in comments.

1 Comment

also [array addObject:[blockIfLoadingImageFromServer copy]];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.