Skip to content

Instantly share code, notes, and snippets.

@jnutting
Created June 11, 2014 08:57
Show Gist options
  • Save jnutting/8b2256433c5de52bf1f9 to your computer and use it in GitHub Desktop.
Save jnutting/8b2256433c5de52bf1f9 to your computer and use it in GitHub Desktop.
dynamic dispatch in swift
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