Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test if a created object is nil

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?

like image 322
Nielsou Hacken-Bergen Avatar asked Jul 04 '11 14:07

Nielsou Hacken-Bergen


People also ask

How do I check if an object is nil in Objective C?

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.

How check object is nil or not in Swift?

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.

How do you test for an empty object in Java?

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.

IS NULL object in Java?

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.


1 Answers

exactly the same with comparing with nil like this

if (!managedObject) {
    NSLog(@"foooo");
}
like image 101
Vijay-Apple-Dev.blogspot.com Avatar answered Sep 30 '22 08:09

Vijay-Apple-Dev.blogspot.com