Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Spooky action at a distance when you don't use self
// Try this in a commandline app vs a playground. The behaviors are different.
class MyClass {
func doSomething() {
refresh() // I wonder which refresh we'll get?
}
}
// Not only does this change the behavior of doSomething()... (see below)
// extension MyClass {
// func refresh() {
// println("I'm an extension refresh")
// }
//}
func refresh() {
println("I'm the global refresh function.")
}
// ... but it behaves *differently* if it's here
//extension MyClass {
// func refresh() {
// println("I'm an extension refresh")
// }
//}
MyClass().doSomething()
// see also https://gist.github.com/rnapier/4213dc64206b17df6935
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.