旋转异步/等待 - 忽略“考虑使用异步替代功能”警告

问题描述 投票:0回答:1
nil

完成完成处理程序。编译器给我发出警告:

Consider using asynchronous alternative function

Task { let foo = await bar() // Yes, using async/await here // Objc method. Completion is nil because I don't care about the result. noNeedToWaitForThis(completion: nil) // WARNING: Consider using asynchronous alternative function }

是否有一种避免此错误的方式?还是将其包装在另一个功能中的唯一选项?

到目前为止,我发现最好的就是使用一个闭合:

Task { ... { noNeedToWaitForThis(completion: nil) // No more warning }() }

这在Xcode13.1.

[编辑]示例目标C方法带回调:

typedef void (^ResponseBlock)(BOOL success, id _Nullable object); - (void)noNeedToWaitForThisWithCompletion:(nullable ResponseBlock)completion;

xcode 14.3的优点,最简单的静音方法是使用
let _ = ...
swift async-await
1个回答
4
投票
不幸的是,现在唯一的途径似乎是匿名关闭:

Task {
   ...
   { noNeedToWaitForThis(completion: nil) }() // Warning is silenced
}


最新问题
© www.soinside.com 2019 - 2025. All rights reserved.