如果你发送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
发布评论