美文网首页
swift中protocol的extension中使用#sele

swift中protocol的extension中使用#sele

作者: 梁森的简书 | 来源:发表于2021-05-06 12:14 被阅读0次

协议扩展

extension AYActionSheetViewProtocol where Self: UIView

不能在上面这样的协议扩展中直接使用#selector,协议扩展对于OC是看不见的。


0.@objc+protocol extension.jpg

其中有个报错:

@objc can only be used with members of classes, @objc protocols, and concrete extensions of classes

@objc只能与类的成员、@objc协议和类的具体扩展一起使用

在@objc协议中使用@objc

@objc protocol AYActionSheetViewProtocol {
    /// 点击半透明背景图
    @objc func tapBackView(tap: UITapGestureRecognizer)
}

协议中tapBackView的具体实现要在遵守了该协议的遵守者中实现。

相关文章

网友评论

      本文标题:swift中protocol的extension中使用#sele

      本文链接:https://www.haomeiwen.com/subject/klxclltx.html