1

我有函数,我将块变量blockIfLoadingImageFromServer添加到数组:

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

然后我想得到这个变量,但我不知道如何。我试过:

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

但这会产生错误(语法错误)。我怎样才能做到这一点?

4

1 回答 1

3

我通常typedef让我的生活更轻松:

typedef void (^ImageBlock)(UIImage*);

进而:

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

- (void) doSomethingElse
{
    ImageBlock block = [array lastObject];
    …
}
于 2012-11-01T11:50:57.600 回答