2016-01-13 84 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"); 
}]; 
相關問題