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

2
  • @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. Commented Aug 30, 2012 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. Commented Aug 30, 2012 at 14:25

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks for quick reply. why my control enter in if condition?
your string contains the characters "(null)". i added more detail in my answer.
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.

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.