2
我正在試圖製作一個UITextField擴展,它在設置委託時執行其他功能。在擴展中的弱屬性上添加didSet觀察器
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
什麼我需要爲Do stuff
改變在委託的設置要打印的?
最終,我試圖看看如何依次調用多個代表(而不是被限制爲一個)。然而無論如何,觀察者模式在這種情況下更強大。 –