考虑以下代码:
class Cat {
var name = "Tom"
}
class Globals {
var cat = Cat()
}
let glob = Globals()
func one () {
Task {glob.cat.name="Max"} // Expected Warning about some nonSendable moving into a different concurrency domain
}
通常情况下,与-warn-concurrency
启用后,Swift/Xcode 会对跨并发域的不可发送内容发出警告。
根据我的理解,传递给的闭包Task
必须始终是一个@Sendable
关闭。 A@Sendable
闭包只能捕获 Sendables。但是,Globals 不是可发送类型。我预计会出现类似以下的警告
在 a 中捕获具有不可发送类型“Globals”的“glob”@Sendable
closure
不会发出此类警告。
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)