加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

我可以在Swift中模拟traits/mixins吗?

发布时间:2020-12-14 05:59:10 所属栏目:百科 来源:网络整理
导读:Swift有一种混合的特性,一个斯卡拉? Swift关于使用扩展来为现有类添加协议的部分非常接近。但是,由于协议不能包含实现,因此不能用于将代码混合到类中。还有别的办法吗? 从Swift 2.0开始,是的! Providing Default Implementations You can use protoco
Swift有一种混合的特性,一个斯卡拉? Swift关于使用扩展来为现有类添加协议的部分非常接近。但是,由于协议不能包含实现,因此不能用于将代码混合到类中。还有别的办法吗?
从Swift 2.0开始,是的!

Providing Default Implementations

You can use protocol extensions to provide a default implementation to any method or property requirement of that protocol. If a conforming type provides its own implementation of a required method or property,that implementation will be used instead of the one provided by the extension.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读