gpt4 book ai didi

ios - 在扩展中的弱属性上添加 didSet 观察者

转载 作者:可可西里 更新时间:2023-11-01 01:37:54 26 4
gpt4 key购买 nike

我正在尝试制作一个 UITextField 扩展,它根据委托(delegate)的设置执行附加功能。

extension UITextField {
override weak public var delegate: UITextFieldDelegate? {
didSet {
print("Do stuff")

}
}
}

这失败了,出现了三个错误:

'delegate' used within its own type

'weak' cannot be applied to non-class type '<<error type>>'

Property does not override any property from its superclass

要在委托(delegate)设置上打印Do stuff,我需要更改什么?

最佳答案

您不能使用扩展覆盖委托(delegate)属性,您需要创建子类:

class TextField: UITextField {
override weak var delegate: UITextFieldDelegate? {
didSet {
super.delegate = delegate
print("Do stuff")
}
}
}

但这似乎有点不对。你想达到什么目的?

关于ios - 在扩展中的弱属性上添加 didSet 观察者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33816609/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com