What's the Difference Between nil and Nil

前端 未结 3 2066
醉话见心
醉话见心 2021-02-12 03:40

In Objective C?

Are they really the same thing?

How to test that an object is nil?

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-12 04:19

    Nil and nil are defined to be the same thing (__DARWIN_NULL), and are meant to signify nullity (a null pointer, like NULL). Nil is meant for class pointers, and nil is meant for object pointers (you can read more on it in objc.h; search for Nil). Finally, you can test for a null value like this:

    if (object == nil)
    

    or like this:

    if (!object)
    

    since boolean evaluations will make any valid pointer that contains an object evaluate to true.

提交回复
热议问题