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

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

问题描述

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

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

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

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、0、0.0 或 NO,具体取决于返回类型.
  • 这篇关于“向 nil 发送消息"是什么意思?意思是,为什么这是一个特例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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