Skip to content

Instantly share code, notes, and snippets.

@younata
Created June 10, 2015 06:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save younata/9a540801f45341659b66 to your computer and use it in GitHub Desktop.
Save younata/9a540801f45341659b66 to your computer and use it in GitHub Desktop.
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