NSPredicate Core Data

独自空忆成欢 提交于 2019-12-03 17:14:00

The difference between LIKE and = in a predicate is that LIKE allows ? and * as wildcard characters, where ? matches 1 character and * matches 0 or more characters.

Both LIKE and = can be modified with [c] to specify case insensitivity.

Example: Assume that you have objects with names

"Mark", "mark", "Mike", "mike", "M*"

Both

[NSPredicate predicateWithFormat:@"name = %@", @"Mark"];
[NSPredicate predicateWithFormat:@"name LIKE %@", @"Mark"];

find "Mark", and both

[NSPredicate predicateWithFormat:@"name =[c] %@", @"Mark"];
[NSPredicate predicateWithFormat:@"name LIKE[c] %@", @"Mark"];

find "Mark" and "mark". But only the LIKE operator can be used with wildcards, e.g.

[NSPredicate predicateWithFormat:@"name LIKE[c] %@", @"M*"];

finds "Mark", "mark", "Mike", "mike" and "M*", but

[NSPredicate predicateWithFormat:@"name ==[c] %@", @"M*"];

finds only "M*".

See String Comparisons in the "Predicate Programming Guide" for more information.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!