Gibt es Möglichkeiten, optionale Methoden im Swift-Protokoll zu überschreiben?Optionale Methoden im Swift-Protokoll und Überlastung
protocol Protocol {
func requiredMethod()
}
extension Protocol {
func optionalMethod() {
// do stuff
}
}
class A: Protocol {
func requiredMethod() {
print("implementation in A class")
}
}
class B: A {
func optionalMethod() { // <-- Why `override` statement is not required?
print("AAA")
}
}
Warum in UIKit gibt es ähnliches Beispiel?
protocol UITableViewDelegate : NSObjectProtocol, UIScrollViewDelegate {
// ......
optional public func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
}
class MyTVC: UITableViewController {
override func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
{}
override
Anweisung erforderlich !!! Aber UITableViewController
reagiert nicht auf Selektor "tableView: estimatedHeightForRowAtIndexPath:"
Was ist ein Problem?
Hier ist ein großartiger Artikel über all dies: [Der Geist der schnellen Fehler Zukunft] (https://nomothetis.svbtle.com/the-ghost-of-swift-bugs-future) – ColGraff
Vielen Dank für diesen Link ! –