5

I have an API

+ (void)getTheThing:(nonnull void (^)(NSString * __nullable thing, NSError * __nullable error))completion;

(Syntax taken from here)

But when go to use it, and take advantage of Xcode's block autocomplete, it autocompletes to this:

[MyAPI getTheThing:^nonnull void(NSString * __nullable, NSError * __nullable) {
    <#code#> 
}];

Which gives errors for nonnull being not recognised, the fact there's not argument names etc...

Any idea what's going on? :S Am I declaring it wrong? This stuff is fairly new, and the documentation isn't really complete :/

Community
  • 1
  • 1
Sam Jarman
  • 7,277
  • 15
  • 55
  • 100

1 Answers1

5

Any idea what's going on?

It is broken http://www.openradar.me/20835509

Am I declaring it wrong?

You could annotate blocks like this:

+ (void)getTheThing:(void (^__nonnull)(NSString * __nullable thing, NSError * __nullable error))completion;

Then autocomplete would produce this code:

[MyAPI getTheThing:^(NSString * __nullable, NSError * __nullable) {
    <#code#> 
}];

It is still broken though. It would probably be faster just to forget about autocomplete and copy and paste your block declaration.

This stuff is fairly new, and the documentation isn't really complete

There is more info on llvm website, but still not enough info on blocks.

kean
  • 1,561
  • 14
  • 22