= vs == in NSPredicate

6
我在苹果文档中看到,他们提到了 === 表现相同。但是在苹果的示例中,在大多数情况下使用 ==,而用 = 进行 nil 检查。对于以下情况,使用 = 安全吗?请参考链接:https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Predicates/Articles/pSyntax.html#//apple_ref/doc/uid/TP40001795-SW1
NSPredicate(format: "firstName = %@", "Bunny")

或者我们应该使用:
NSPredicate(format: "firstName == %@", "Bunny")

在处理谓词时,两者之间有什么区别吗?

1个回答

9

在 NSPredicate 中使用时,它们是等价的。我想使用 == 会稍微更受欢迎,因为与其他 Swift 代码结合使用时会“看起来”更正确。但是两种方式都可以安全使用。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接