swift class extension 与继承

1、扩展中无法继承重写已有函数,不能添加函数。

Extensions can add new functionality to a type, but they cannot override existing functionality.

https://docs.swift.org/swift-book/LanguageGuide/Extensions.html

2、扩展函数的可见性:全局可见

If you define an extension to add new functionality to an existing type, the new functionality will be available on all existing instances of that type, even if they were created before the extension was defined.

3、扩展中函数可以有条件被继承

dynamic 可以让声明在 extension 里面的函数能够被 override.

https://www.jianshu.com/p/91bfe3f11eec

4、扩展只可以添加计算属性:

Extensions can add new computed properties, but they cannot add stored properties, or add property observers to existing properties.

https://docs.swift.org/swift-book/LanguageGuide/Extensions.html

转载于:https://www.cnblogs.com/feng9exe/p/9675397.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值