-3

as I am working myself into some new code, I came across a thing, where I couldnt find any explanation for in the web so far. So hopefully you can give me one.

I have this method signature in Objective-C code:

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

Can someone please tell me what it is about in the last parameter?

Thanks a lot!

tellob
  • 1,220
  • 3
  • 16
  • 32
  • 2
    https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/WorkingwithBlocks/WorkingwithBlocks.html – Larme Jan 13 '16 at 16:37
  • 1
    See also [Block declaration syntax list](http://stackoverflow.com/q/9201514) – jscs Jan 13 '16 at 19:59

1 Answers1

1

It is a block that takes a BOOL argument and returns void. See the documentation for more info on the syntax.

When invoking this method, you can provide a callback through this block. This will let you submit code to be executed after the method has run.

For example:

[self supportsUrl:@"http://www.google.com" callback:^(BOOL supported){
    if (supported) NSLog(@"Yay, supported");
    else NSLog(@"Nay, not supported");
}];
Hamish
  • 78,605
  • 19
  • 187
  • 280