首页 > 解决方案 > 如何修复不兼容的块指针类型发送错误

问题描述

由于不兼容的块指针类型发送错误,构建失败。

- (void)loadAndConfigureWithCompletion:(void (^ _Nonnull)(BOOL, NSError * _Nullable))completion;
[SkyIdConfigure.shared loadAndConfigureWithCompletion:^(BOOL *isConfigured,NSError *error){
    if (error) {
    }
    if (isConfigured) {
    }
}];

我有这个错误!

Incompatible block pointer types sending 'int (^)(BOOL *, NSError * _Nullable)' to parameter of type 'void (^ _Nonnull)(BOOL, NSError * _Nullable)' Incompatible block pointer types sending 'void (^)(BOOL *, NSError *)' to parameter of type 'void (^ _Nonnull)(BOOL, NSError * _Nullable)'

标签: iosobjective-cxcodeobjective-c-blocks

解决方案


让我们接收一条错误消息!

一点提示,将预期和当前放在另一个之上,这样会更容易发现差异。当我无法发现差异时,我会这样做。

Incompatible block pointer types sending 'void (^)(BOOL *, NSError *)' to parameter of type 'void (^ _Nonnull)(BOOL, NSError * _Nullable)'

=>

Incompatible block pointer types sending 
'void (^)(BOOL *, NSError *)' 
to parameter of type 
'void (^ _Nonnull)(BOOL, NSError * _Nullable)'

=>

'void (^)(BOOL *, NSError *)'                  //You wrote
'void (^ _Nonnull)(BOOL, NSError * _Nullable)' //Expected

=>

'void (^         )(BOOL *, NSError *          )' //You wrote
'void (^ _Nonnull)(BOOL  , NSError * _Nullable)' //Expected
                        ^
                        |____________________________
                                                     |

Nonnull/ Nullable,这是一回事,但你注意到*布尔值的额外部分了吗?你有一个指针,你有直接的价值。

[SkyIdConfigure.shared loadAndConfigureWithCompletion:^(BOOL *isConfigured, NSError *error) {
}];

=>

[SkyIdConfigure.shared loadAndConfigureWithCompletion:^(BOOL isConfigured, NSError *error) {
}];

推荐阅读