Difference between nil and null

Possible duplicate:
NULL vs nil in Objective-C
Objective-C: What is the difference between NULL, nil and @ ""?

I have a simple problem that my object variable is NULL . and it just enters the if condition . I must verify that if the variable object length is greater than zero and not null, enter a condition.

and when do i use null or nil in comparison ?

thanks

enter image description here

+6
source share
3 answers

They are the same. However, it is traditional to use nil to compare with the objc object and when assigning to the objc object.

+5
source

Assuming we're talking about Objective-C:

nil (all lowercase letters) is a null pointer to an Objective-C object.

nil (capized) is a null pointer to an Objective-C class.

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

+4
source

In this case, it seems that you have a string with the value "(null)". This can happen if you are trying to add or format the contents of the string that was the most null. This is a valid string that is not NULL or nil and has a length of 8 characters. Thus, it enters your cycle.

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

+1
source

Source: https://habr.com/ru/post/923862/


All Articles