I am using this code
if (managedObject == nil) {
NSLog(@"foooo");
}
to test if the created managedObject is nil or not. But I can never print this Fooooo. Do you know what I am doing wrong?
As this answer says: Any message to nil will return a result which is the equivalent to 0 for the type requested. Since the 0 for a boolean is NO, that is the result.
In Swift, you can also use nil-coalescing operator to check whether a optional contains a value or not. It is defined as (a ?? b) . It unwraps an optional a and returns it if it contains a value, or returns a default value b if a is nil.
The isEmpty() method of Properties class is used to check if this Properties object is empty or not. Returns: This method returns a boolean value stating if this Properties object is empty or not.
No , null is not an object.It is a reference type and its value does not refer to any object and so there is no representation of null in memory.
exactly the same with comparing with nil like this
if (!managedObject) {
NSLog(@"foooo");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With