Created
August 26, 2014 18:55
-
-
Save alexito4/2dbab8d961c4c060e5c3 to your computer and use it in GitHub Desktop.
Swift extensions and inheritance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
protocol Thing { | |
func name() -> String | |
} | |
protocol God { | |
func talk() -> String | |
} | |
class Base : Thing { | |
func a() -> String { | |
return "Base A" | |
} | |
func name() -> String { | |
return "base name" | |
} | |
} | |
extension Base : God { | |
func talk() -> String { | |
return "base talk" | |
} | |
} | |
class Child : Base { | |
override func a() -> String { | |
return "child A" | |
} | |
override func name() -> String { | |
return "child name" | |
} | |
override func talk() -> String { | |
return "child talk" | |
} | |
} | |
let base = Base() | |
base.a() | |
base.name() | |
base.talk() | |
let child = Child() | |
child.a() | |
child.name() | |
child.talk() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice example. I see you are strong in this. Could you please help me with question below?
I have 2 classes and 1 extension. Like following:
I believe here is something wrong with inheritance but I don't know what.
If you have some thoughts could you please share it with me.
Thank you in advance.