当我自己编写一些新代码时,我遇到了一个问题,到目前为止我在网上找不到任何解释。所以希望你能给我一个。
我在Objective-C代码中有这个方法签名:
-(void) supportsUrl: (NSString*) url callback:(void (^)(BOOL supported)) callback;
有人可以告诉我最后一个参数是什么吗?
非常感谢!
答案 0 :(得分:1)
这是一个采用BOOL
参数并返回void
的块。 See the documentation for more info on the syntax.
调用此方法时,可以通过此块提供回调。这将允许您提交在方法运行后要执行的代码。
例如:
[self supportsUrl:@"http://www.google.com" callback:^(BOOL supported){
if (supported) NSLog(@"Yay, supported");
else NSLog(@"Nay, not supported");
}];