They differ in their types. They're all zero, but NULL
is a void *
, nil
is an id
, and Nil
is a Class pointer.
各种类型的不存在的表示。
理解“不存在”的概念不仅仅是一个哲学的问题,也是一个实际的问题。我们是 有形 宇宙的居民,而原因在于逻辑宇宙的存在不确定性。作为一个逻辑系统的物理体现,电脑面临一个棘手的问题,就是如何用 存在 表达 不存在 .
在 Objective-C 中,有几个不同种类的 不存在。
They both are just typecast zero's. Functionally, there's no difference between them. ie.,
#define NULL ((void*)0) #define nil ((id)0)
There is a difference, but only to yourself and other humans that read the code, the compiler doesn't care.
One more thing nil is an object value while NULL is a generic pointer value.
https://stackoverflow.com/questions/1564410/when-should-i-use-nil-and-null-in-objective-c
来源:oschina
链接:https://my.oschina.net/u/4321696/blog/3302278