I usually use [NSNull new
] if I want a NSNull
object, but today I noticed that NSNull
class provided a class method [NSNull null]
to create a NSNull
object.
I wonder what is the difference between [NSNull new]
and [NSNull null]
? is it a wrong way to use [NSNull new]
to create an NSNull
object?
By the documentation,
[... new]
equals[[... alloc] init]
and creates and returns a new instance for any class that inherits from theNSObject
.[NSNull null]
is a singleton instance that always returns the same instance which is thekCFNull
. but if you see the documentation of theNSNull
, you can see:So because of the nature of the
NSNull
, all of them are the same by the instance:Note how all of them are pointing to the exact same location