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

前端 未结 6 1957
北恋
北恋 2020-12-02 23:04

As the title says, what\'s the difference between NULL, nil and @\"\" ?

For example, if I want to check a string in a dictiona

6条回答
  •  我在风中等你
    2020-12-03 00:01

    "The NSNull class defines a singleton object you use to represent null values in situations where nil is prohibited as a value (typically in a collection object such as an array or a dictionary)." You can use nil about anywhere you can use null. The main difference is that you can send messages to nil, so you can use it in some places where null cant work. In general, just use nil. that's exactly what's happening, the programmer is choosing to put a null object into the controllers array, where nil is not allowed as a value.

    It is more a contextual reference where NULL is a pointer to 0x0, nil is a non-existent objective-c object and Nil is a non-existent objective-c class, but technically they are all just 0. Also, it is NULL not null -- null is in Java or C# but not in Objective-C

    or ease ways u say

    They're all zero, but "NULL" is a void *, "nil" is an id, and "Nil" is a Class pointer.

提交回复
热议问题