Compiler error when assigning the Delegate for a Protocol in Swift iOS

后端 未结 1 1670
醉话见心
醉话见心 2021-01-27 22:59

I have a problem assigning the delegate for an object that is an instance of a class that defines a protocol in Swift as follows:

I simplified the code to the bare bones

相关标签:
1条回答
  • 2021-01-28 00:02

    The Known Issues section of the Release Notes says:

    You cannot conditionally assign to a property of an optional object. (16922562)

    For example, this is not supported:

    let window: NSWindow? = NSApplication.sharedApplication.mainWindow
    window?.title = "Currently experiencing problems"
    

    So you should do something like if let realObject = object { ... }

    0 讨论(0)
提交回复
热议问题