美文网首页
swift 给protocol方法默认实现

swift 给protocol方法默认实现

作者: 喵喵粉 | 来源:发表于2020-06-24 15:06 被阅读0次

swift遵守协议时,需要把协议中的方法都写一遍,

可以在extension中为protocol默认实现,

协议方法都类似可选的。

protocol BannerViewProtocol: class {
    func bannerViewSelectUrl(_ url: String, isVideo: Bool)
}

extension BannerViewProtocol {
    func bannerViewSelectUrl(_ url: String, isVideo: Bool) {}
}

相关文章

网友评论

      本文标题:swift 给protocol方法默认实现

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