7

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

Community
  • 1
  • 1
QueueOverFlow
  • 1,336
  • 5
  • 27
  • 48
  • @Brad Larson. First a Fall you are my favorite programmer. second thing is that. I asked that question after 1 hour googling. I ask this question here to get solution of my problem and understanding the concept why control enter in my if condition. It is not possible that user can see all the questions related to any topic. I simply wants to say, that I am not copying anyone to earn point in stack over flow. Thanks. – QueueOverFlow Aug 30 '12 at 10:15
  • 1
    There was nothing wrong with your question, it's just been asked before in a couple of different ways, so I wanted to direct people to the original questions. This helps keep good answers in one place for people who search for the same thing. There was a copied answer here, which is what alerted me to the fact that this was asking something similar to what these two questions had. – Brad Larson Aug 30 '12 at 14:25

3 Answers3

5

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

justin
  • 104,054
  • 14
  • 179
  • 226
4

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.

khr055
  • 28,690
  • 16
  • 36
  • 48
Akram Khan
  • 61
  • 3
1

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.

Sparky
  • 172
  • 15
madmik3
  • 6,975
  • 3
  • 38
  • 60