What's the Difference Between nil and Nil

前端 未结 3 2080
醉话见心
醉话见心 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:03

    nil is the Objective-C constant for a null pointer to an object, Nil is identically defined. In practice, it is has the same value as the C constant NULL. Test for a nil object like this:

    if (fooObj == nil)
    

    In my code, I tend to use nil for Objective-C objects and NULL for other C pointers. This is a matter of personal taste - currently nil and NULL are interchangeable for comparison in all existing Objective-C implementations.

提交回复
热议问题