Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between nil and NULL [duplicate]

Tags:

ios

iphone

Possible Duplicate:
NULL vs nil in Objective-C
Objective-C: What's the difference between NULL, nil and @“”?

all I have a simple problem that my objective variable has NULL value in it. and it simply enter in the if condition. I have to check that if variable objective length is greater then zero and no null value then enter in condition.

and When I use NULL or nil in comparison?

THANKS

enter image description here

like image 336
QueueOverFlow Avatar asked Aug 27 '12 12:08

QueueOverFlow


3 Answers

They are the same. However, it is conventional to use nil to compare against an objc object, and when assigning to an objc object.

like image 155
justin Avatar answered Sep 19 '22 18:09

justin


Assuming we're talking about Objective-C:

nil (all lower-case) is a null pointer to an Objective-C object.

Nil (capitalized) is a null pointer to an Objective-C class.

NULL (all caps) is a null pointer to anything else.

like image 45
Akram Khan Avatar answered Sep 20 '22 18:09

Akram Khan


In this case it seems that you have a string with a value of "(null)". This can happen when you attempt to append or format content into the string that was null itself. It's a valid string that is not NULL or nil and is 8 characters long. So it enters your loop.

In objective-c, NULL and nil are the same thing (the number 0). But the style guide will tell you to use NULL for pointers and nil for classes derived from NSObject.

like image 23
madmik3 Avatar answered Sep 20 '22 18:09

madmik3