swift 可选协议

2021-12-24  本文已影响0人  孤雁_南飞

前言

xcode 13.2.1
swift 5.4

swift 协议

 protocol YLLiveStreamListCellDelegate: NSObjectProtocol { 
   func LiveStreamListCell(_ cell: YLLiveStreamListCell)
}

swift可选协议

协议前添加 @objc ,把你想要改成的可选协议前添加 @objc optional 即可

@objc protocol YLLiveStreamListCellDelegate: NSObjectProtocol { 
    @objc optional func LiveStreamListCell(_ cell: YLLiveStreamListCell)
}

swift 可选协议限制

swfit 独有的类型不可设置可选协议,例如 tuple,

Method cannot be marked @objc because the type of the parameter 2 cannot be represented in Objective-C

方法无法标记为 @objc,因为参数 2 的类型无法在 Objective-C 中表示
在这里插入图片描述
上一篇 下一篇

猜你喜欢

热点阅读