我有函数,我将块变量 blockIfLoadingImageFromServer 添加到数组中:
- (UIImage *)getImageWithblockIfLoadingImageFromServer:(void (^)(UIImage *imageCompleted))blockIfLoadingImageFromServer
{
[array addObject:blockIfLoadingImageFromServer];
}
然后我想得到这个变量,但我不知道如何。我试过了:
(void (^)(UIImage *imageCompleted))blockIfLoadingImageFromServer = [array objectAtIndex:0];
void (^)(UIImage *imageCompleted) *blockIfLoadingImageFromServer = [array objectAtIndex:0];
但是这会产生错误(语法错误)。我怎么能这样做?
答案 0 :(得分:3)
我通常typedef
让我的生活更轻松:
typedef void (^ImageBlock)(UIImage*);
然后:
- (void) doSomethingWithBlock: (ImageBlock) block
{
[array addObject:[block copy]];
}
- (void) doSomethingElse
{
ImageBlock block = [array lastObject];
…
}