Created
June 11, 2014 08:57
-
-
Save jnutting/8b2256433c5de52bf1f9 to your computer and use it in GitHub Desktop.
dynamic dispatch in swift
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
class A { | |
func foo() -> String { | |
return "A foo" | |
} | |
} | |
class B: A { | |
override func foo() -> String { | |
return "B foo" | |
} | |
} | |
let a = A() | |
let aFoo = a.foo() // "A foo" | |
let b = B() | |
let bFoo = b.foo() // "B foo" | |
let b2 = B() as A | |
let b2Foo = b2.foo() // "B foo" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment