2016-01-13 76 views
-3

因为我正在自己研究一些新的代码,所以我遇到了一件事情,到目前为止我无法在网络中找到任何解释。所以希望你能给我一个。(void(^)(BOOL支持))是什么意思?

我在Objective-C代码此方法签名:

-(void) supportsUrl: (NSString*) url callback:(void (^)(BOOL supported)) callback; 

有人能告诉我它是什么在最后一个参数?

非常感谢!

+2

https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/WorkingwithBlocks/WorkingwithBlocks.html – Larme

+1

参见[块声明语法列表]( http://stackoverflow.com/q/9201514) –

回答

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"); 
}]; 
相关问题