How to find out if the address of an object is 0x0?

I want to check if my object address is 0x0. How to do this in objective c?

+3
source share
4 answers

Just compare the link as

if (obj == nil)

or

if (obj == NULL)

or

if (obj == 0)

or

if (!obj)

You can use any of them, they are all the same.

+5
source
if(object == nil){

// it means memory for this object is not allocated 

}
+3
source

You can check the null pointer as follows:

if (!myObject) {
    // myObject is nil (0x0).
}

Or like this:

if (myObject == nil) {
    // myObject is nil (0x0).
}
+2
source

this address is zero, so you need to compare it with nil

+2
source

All Articles