在基于块的 API 中使用可空性
Using nullability with block based APIs
我有一个API
+ (void)getTheThing:(nonnull void (^)(NSString * __nullable thing, NSError * __nullable error))completion;
(语法取自 )
但是当去使用它时,利用 Xcode 的块自动完成,它自动完成为:
[MyAPI getTheThing:^nonnull void(NSString * __nullable, NSError * __nullable) {
<#code#>
}];
这给出了 nonnull
无法识别的错误,事实上没有参数名称等...
知道发生了什么事吗? :S 我声明错了吗?这些东西是相当新的,documentation 还不是很完整:/
Any idea what's going on?
坏了http://www.openradar.me/20835509
Am I declaring it wrong?
您可以像这样注释块:
+ (void)getTheThing:(void (^__nonnull)(NSString * __nullable thing, NSError * __nullable error))completion;
然后自动完成将生成此代码:
[MyAPI getTheThing:^(NSString * __nullable, NSError * __nullable) {
<#code#>
}];
不过还是坏了。忘记自动完成并复制并粘贴您的块声明可能会更快。
This stuff is fairly new, and the documentation isn't really complete
llvm 网站上有更多信息,但块上的信息仍然不够。
我有一个API
+ (void)getTheThing:(nonnull void (^)(NSString * __nullable thing, NSError * __nullable error))completion;
(语法取自
但是当去使用它时,利用 Xcode 的块自动完成,它自动完成为:
[MyAPI getTheThing:^nonnull void(NSString * __nullable, NSError * __nullable) {
<#code#>
}];
这给出了 nonnull
无法识别的错误,事实上没有参数名称等...
知道发生了什么事吗? :S 我声明错了吗?这些东西是相当新的,documentation 还不是很完整:/
Any idea what's going on?
坏了http://www.openradar.me/20835509
Am I declaring it wrong?
您可以像这样注释块:
+ (void)getTheThing:(void (^__nonnull)(NSString * __nullable thing, NSError * __nullable error))completion;
然后自动完成将生成此代码:
[MyAPI getTheThing:^(NSString * __nullable, NSError * __nullable) {
<#code#>
}];
不过还是坏了。忘记自动完成并复制并粘贴您的块声明可能会更快。
This stuff is fairly new, and the documentation isn't really complete
llvm 网站上有更多信息,但块上的信息仍然不够。