【发布时间】:2021-05-25 20:59:37
【问题描述】:
我想扩展我在该对象上工作的基类 (UIView) 并返回具有正确类型的调用对象
extension UIView {
func withCleanBg() -> UIView {
self.backgroundColor = .clear
return self;
}
}
例如,如果我调用 let btn:UIButton = UIButton().withCleanBg(),我希望 btn 在调用扩展后保持 UIButton 而不是 UpCasted。
我希望它链接函数调用,例如
UIButton().withCleanBg().withFillInParent()等等
【问题讨论】:
-
与您的问题无关,但考虑到没有参数,您应该使用计算属性而不是 e 函数