发送isEqual:到nil总是返回NO

编程入门 行业动态 更新时间:2024-10-25 19:20:18
本文介绍了发送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

本文发布于:2023-10-19 19:19:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1508511.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:isEqual   nil

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!