【问题标题】:Code Block error with iOS 9iOS 9 的代码块错误
【发布时间】:2015-09-22 11:54:06
【问题描述】:

在 iOS 9 发布 (Xcode 7.0) 后,我们在应用商店中的应用会间歇性崩溃,当我们尝试使用 iOS 9 编译我们的代码库时,我们会在这段代码中看到编译器错误

/* Check for dependent errors */
    __block NSError *dependentError = nil;
    [self.dependencies enumerateObjectsUsingBlock:^(CustomBaseOperationLoader *operation, NSUInteger idx, BOOL *stop) {
        if (operation.operationError != nil) {
            dependentError = [operation.operationError copy];
            *stop = YES;
        }
    }];

不兼容的块指针类型发送'void (^)(CustomBaseOperationLoader *__strong, NSUInteger, BOOL *)' 到 'void (^ _Nonnull)(NSOperation * _Nonnull __strong, NSUInteger, BOOL * _Nonnull)'

iOS 新手,还有其他人面临这个问题或知道如何解决这个问题吗? 在 iOS 9 更新之前我们没有看到它,因此某些地方已弃用。

并且CustomBaseOperationLoader 扩展了NSOperation 一些自定义属性

更新: 根据以下答案,我将方法调用更改为

__block NSError *dependentError = nil;
    [self.dependencies enumerateObjectsUsingBlock:^ _Nonnull(CustomBaseLoaderOperation * _Nonnull operation, NSUInteger  idx, BOOL * _Nonnull stop) {
        if (operation.operationError != nil) {
            dependentError = [operation.operationError copy];
            *stop = YES;
        }
    }];

现在我明白了:

控制到达非空块的末尾

更新 2: 添加了一个返回块,这似乎解决了错误 这是正确的处理方式吗?

/* Check for depended errors */
    __block NSError *dependentError = nil;
    [self.dependencies enumerateObjectsUsingBlock:^ _Nonnull(CustomBaseLoaderOperation * _Nonnull operation, NSUInteger  idx, BOOL * _Nonnull stop) {
        if (operation.operationError != nil) {
            dependentError = [operation.operationError copy];
            *stop = YES;
        }
        return;
    }];

更新: 现在 xcode 刚刚在

clang: error: unable to execute command: Segmentation fault: 11
clang: error: clang frontend command failed due to signal (use -v to see invocation)

还不确定该去哪里

【问题讨论】:

标签: ios objective-c ios9


【解决方案1】:

添加可空性注释。

 [yourArray enumerateObjectsUsingBlock:^_Nonnull(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        //your stuff
    }];

【讨论】:

  • 好吧,我将 _Nonnull 添加到方法块本身,现在我看到 Control reaches end of non-void block
  • 通过在 enumerateObjectsUsingBlock 之后添加 _Nonnull 解决。谢谢。也可以在块后添加返回以防止Control reaches end of non-void block 吗?
猜你喜欢
  • 1970-01-01
  • 2015-12-09
  • 2018-07-05
  • 2018-03-26
  • 1970-01-01
  • 2015-12-11
  • 1970-01-01
  • 2018-02-27
  • 1970-01-01
相关资源
最近更新 更多