“将消息发送为零"是什么意思?是什么意思,为什么是特例? [英] What does "sending a message to nil" mean, and why is it a special case?

查看:308
本文介绍了“将消息发送为零"是什么意思?是什么意思,为什么是特例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始阅读Objective-C教程,其中有一节向nil发送消息":

I just started reading the Objective-C tutorials, and there is a section on "sending a message to nil":

可可中有几种模式 利用这一事实.这 从消息返回到nil的值 可能也有效:

There are several patterns in Cocoa that take advantage of this fact. The value returned from a message to nil may also be valid:

这是什么意思?我似乎无法遵循.

What does this mean? I can't seem to follow it.

推荐答案

  • nil基本上是一个空指针(即它是存储在指针中的数字零).
  • 所有发送到nil的消息都是合法的(它们不会导致崩溃),但是它们什么也没做.
  • 所有返回nil的消息均返回nil,或者0、0.0,或NO,具体取决于返回类型.
  • 这篇关于“将消息发送为零"是什么意思?是什么意思,为什么是特例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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