核心数据NSPredicate
中LIKE [c]%@
和= [c]%@
之间的确切区别是什么?我想搜索一个与接收者完全匹配的字符串。
示例:
NSArray *arrayNames = [context fetchObjectsForEntityName:NSStringFromClass([PatientFamilyMember class])
withSortColumn:nil withSortDescending:FALSE
withPredicate:@"patientID = %@ && firstName=[c]%@ && relationship=[c]%@ && lastName=[c]%@",
self.pfm.patientID, firstName, relationship, lastName];
这可行,但我不明白使用 LIKE [c]
和 = [c]%@.
最佳答案
谓词中 LIKE
和 =
之间的区别在于 LIKE
允许 ?
和 *
作为通配符,其中 ?
匹配 1 个字符,*
匹配 0 个或多个字符。
LIKE
和 =
都可以使用 [c]
进行修改,以指定不区分大小写。
示例:假设您有带有名称的对象
"Mark", "mark", "Mike", "mike", "M*"
两者
[NSPredicate predicateWithFormat:@"name = %@", @"Mark"];
[NSPredicate predicateWithFormat:@"name LIKE %@", @"Mark"];
找到“Mark”,两者都
[NSPredicate predicateWithFormat:@"name =[c] %@", @"Mark"];
[NSPredicate predicateWithFormat:@"name LIKE[c] %@", @"Mark"];
找到“标记”和“标记”。但只有 LIKE
运算符可以与通配符一起使用,例如
[NSPredicate predicateWithFormat:@"name LIKE[c] %@", @"M*"];
找到“Mark”、“mark”、“Mike”、“mike”和“M*”,但是
[NSPredicate predicateWithFormat:@"name ==[c] %@", @"M*"];
仅找到“M*”。
参见String Comparisons有关详细信息,请参阅“谓词编程指南”。
关于iphone - NSPredicate 核心数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14578513/