Hi, I'm interesting in the behavior of the swift extension,
I was wondering what will swift do when we have multiple implementations of one method in different extensions.
Here is the code,
protocol Hello {
func hello()
}
extension Hello {
func hello() {
print("hello")
}
}
protocol Namable {
var name: String { get }
}
extension Namable {
var name: String {
return "wang"
}
}
extension Hello where Self: Namable {
func hello() {
print("hello, \(name)")
}
}
class A: Hello {
}
class B: A, Namable {
}
B().hello()
Can we make sure the B().hello() will call the method in
extension Hello where Self: Namable {
func hello() {
print("hello, \(name)")
}
}
?
Best Regards.