【问题标题】:= vs == in NSPredicate= vs == 在 NSPredicate 中
【发布时间】:2017-10-09 20:57:09
【问题描述】:

我在苹果文档中看到他们提到=== 的行为相同。 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")

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

【问题讨论】:

    标签: ios cocoa core-data


    【解决方案1】:

    在 NSPredicate 中使用时它们是等价的。我想== 可能会有轻微的偏好,因为当与其他 Swift 代码结合使用时,它会“看起来”更正确。但两者都可以安全使用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多