nil 和 Nil 有什么区别 [英] What's the Difference Between nil and Nil

查看:48
本文介绍了nil 和 Nil 有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在目标 C 中?

它们真的是一回事吗?

如何测试一个对象是否为零?

How to test that an object is nil?

推荐答案

Nilnil 被定义为同一个东西(__DARWIN_NULL),并表示无效(空指针,如 NULL).Nil 用于类指针,nil 用于对象指针(您可以在 objc.h;搜索 Nil).最后,您可以像这样测试空值:

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)

或者像这样:

if (!object)

因为布尔计算将使包含对象的任何有效指针的计算结果为真.

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

这篇关于nil 和 Nil 有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆