函数类型在属性中的可发送性与协议中的要求不匹配。

huangapple go评论49阅读模式
英文:

Sendability of function types in property does not match requirement in protocol

问题

我正在尝试添加一个协议,该协议具有Process的所有属性和函数,但我看到了关于terminationHandler的警告。

我希望不会看到这个警告,因为@Sendable已经添加到了terminationHandler

英文:

I am trying to add a protocol which has all the attributes and functions of a Process but I see a warning with terminationHandler.

I was hoping not to see this warning since @Sendable is already added to terminationHandler.

protocol ProcessProtocol {
    var executableURL: URL? { get set }
    var arguments: [String]? { get set }
    var environment: [String : String]? { get set }
    var currentDirectoryURL: URL? { get set }
    var standardInput: Any? { get set }
    var standardOutput: Any? { get set }
    var standardError: Any? { get set }
    func run() throws
    func interrupt()
    func terminate()
    func suspend() -> Bool
    func resume() -> Bool
    var processIdentifier: Int32 { get }
    var isRunning: Bool { get }
    var terminationStatus: Int32 { get }
    var terminationReason: Process.TerminationReason { get }
    var terminationHandler: (@Sendable (Process) -> Void)? { get set }
    var qualityOfService: QualityOfService { get set }
}

extension Process: ProcessProtocol {}

答案1

得分: 1

以下是翻译好的内容:

这确实有点奇怪,因为您的协议签名与开发者文档中Process - terminationHandler所示的签名完全匹配。移除@Sendable注释实际上解决了警告,不太清楚为什么。我会向Apple提交一个关于此问题的错误报告。

英文:

It is a bit odd indeed, because your protocol signature exactly matches what the Developer Documentation signature shows for Process - terminationHandler. Removing the @Sendable notation actually resolves the warning, not sure why. I'd submit a bug report to Apple regarding this.

huangapple
  • 本文由 发表于 2023年5月15日 13:28:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/76251095.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定