Created
June 10, 2015 06:08
-
-
Save younata/9a540801f45341659b66 to your computer and use it in GitHub Desktop.
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 Foo: NSObject { | |
var obj: NSObject? = nil | |
} | |
func createObjectOfType(type: NSObject.self) -> Foo { | |
let obj = type() | |
if obj.respondsToSelector("obj") { | |
obj.setValue(NSObject(), forKey: "obj") // never gets called | |
} | |
//obj.setValue(NSObject(), forKey: "obj") // Exceptions if you don't call it with 'Foo.self' | |
} | |
let fooObject = createObjectOfType(Foo.self) as! Foo | |
println("\(foo.obj)") // nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment