Swift 3, , , , , Swift 4 , . , .
, Swift 4 Objective-C. Swift 3, NSObject, Objective-C . Swift .
, Swift 4 , @objc
, Objective-C, Swift: .
Armed with this knowledge, the solution to your problem is to mark the functions in the extension that you want to override as @objc
, and then override this function in the child classes, but remember to include the tag @objc
so your code will be called at runtime.
WARNING Here's a little work: if you forget to include @objc
in override
, the compiler will not complain, but your code will not have a dynamic search, so it will never be called at runtime.
So your code should look something like this:
class BaseCell: UITableViewCell {
}
extension BaseCell {
@objc func isValid() -> String? {
}
}
class SampleCell: BaseCell {
@obcj override func isValid() -> String? {
}
}
source
share