NSPredicate 与领域中的任何
NSPredicate with ANY in Realm
我在 Realm
中使用 NSPredicate
时出现异常:
Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'Unable to parse the format string "ANY phones.number CONTAINS %@)"'
人 class:
class Person: RLMObject {
...
dynamic var phones = RLMArray(objectClassName: Phone.className())
}
Phone class:
class Phone: RLMObject {
dynamic var number = ""
dynamic var formattedNumber = ""
}
和phone构造的谓词:
func phonesPredicate(#searchString:String) -> NSPredicate {
let searchPredicate = NSPredicate(format: "ANY phones.number CONTAINS %@)", searchString)
return searchPredicate
}
您的格式字符串中有一个错误的右括号。
我在 Realm
中使用 NSPredicate
时出现异常:
Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'Unable to parse the format string "ANY phones.number CONTAINS %@)"'
人 class:
class Person: RLMObject {
...
dynamic var phones = RLMArray(objectClassName: Phone.className())
}
Phone class:
class Phone: RLMObject {
dynamic var number = ""
dynamic var formattedNumber = ""
}
和phone构造的谓词:
func phonesPredicate(#searchString:String) -> NSPredicate {
let searchPredicate = NSPredicate(format: "ANY phones.number CONTAINS %@)", searchString)
return searchPredicate
}
您的格式字符串中有一个错误的右括号。