gpt4 book ai didi

ios - iOS 9 的代码块错误

转载 作者:行者123 更新时间:2023-11-29 10:25:16 24 4
gpt4 key购买 nike

在 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;
}
}];

Incompatible block pointer types sending 'void (^)(CustomBaseOperationLoader *__strong, NSUInteger, BOOL *)' to parameter of type '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;
}
}];

现在我明白了:

Control reaches end of non-void block

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

/* 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)

还不确定去哪里

最佳答案

添加可空性注释。

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

关于ios - iOS 9 的代码块错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32716198/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com