-
-
Save jiverson/69924c43dbe3975fc03c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Cocoa | |
// Only needed until we have class variables | |
var __SwizzleSayHello = { (who:String) -> String in | |
return "Hello, \(who)" | |
} | |
class Swizzle { | |
//Only needed until we have class variables | |
class var _sayHello : (String)->String { get{ return __SwizzleSayHello } set (swizzle) {__SwizzleSayHello = swizzle} } | |
func sayHello(who:String)->String{ | |
return Swizzle._sayHello(who) | |
} | |
} | |
let immutableInstance = Swizzle() | |
var mutableInstance = Swizzle() | |
//Both print "Hello, World" | |
println(immutableInstance.sayHello("World")) | |
println(mutableInstance.sayHello("World")) | |
Swizzle._sayHello = { (who:String) -> String in | |
return "Howdy, \(who)" | |
} | |
//Both print "Howdy, World" | |
println(immutableInstance.sayHello("World")) | |
println(mutableInstance.sayHello("World")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment