我在 apple 文档中看到他们提到 =
,==
的行为相同。
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Predicates/Articles/pSyntax.html#//apple_ref/doc/uid/TP40001795-SW1
但在 apple 示例中,他们在大多数情况下使用 ==
和 =
进行 nil 检查。
在以下情况下使用 =
是否安全?
NSPredicate(format: "firstName = %@", "Bunny")
或者我们应该使用:
NSPredicate(format: "firstName == %@", "Bunny")
两者在处理谓词时有什么区别吗?
最佳答案
它们在 NSPredicate 中使用时是等价的。我想 ==
可能会有轻微的偏好,因为当与其他 Swift 代码结合使用时,它会“看起来”更正确。但两者都可以安全使用。
关于ios - = vs == 在 NSPredicate 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46654860/