发送isEqual:到nil总是返回NO [英] Sending isEqual: to nil always returns NO

查看:164
本文介绍了发送isEqual:到nil总是返回NO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果你发送isEqual:给一个恰好是nil的对象,你总是得到NO。

If you send isEqual: to an object that happens to be nil, you always get NO back.

这是预期的行为吗?要成为一个功能而不是一个错误,我会期望它返回是如果其他对象也是nil,否则否则?语义上这似乎是正确的行为。

Is this the expected behavior? To be a feature instead of a bug, I would expect it to return YES if the other object is also nil, and NO otherwise? Semantically this seems the correct behavior.

如果我的期望不正确,推荐的过程?发送isEqual:(和朋友)之前检查nil?

In case my expectations are incorrect, what the recommended proceedure? Check for nil before sending isEqual: (and friends)?

推荐答案

是的,这是预期的行为。对nil的任何消息将返回一个结果,对于请求的类型,结果等于0。因为布尔值的0是NO,那就是结果。

Yes, this is the expected behavior. Any message to nil will return a result which is the equivalent to 0 for the type requested. Since the 0 for a boolean is NO, that is the result.

这篇关于发送isEqual:到nil总是返回NO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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