如何使用NSPredicate在CoreData中查找标题

时间:2013-01-12 23:20:11

标签: ios core-data nspredicate

如果我想在字符串中找到“color”这个词“红色是我蜡笔盒中的颜色”,我该如何构建它?

谢谢,

1 个答案:

答案 0 :(得分:2)

NSString *stringToSearchFor = @"whatever you want";

[NSPredicate predicateWithFormat:@"name CONTAINS[cd] %@", stringToSearchFor];

寻找红色或法拉利......

NSPredicate *redPred = [NSPredicate predicateWithFormat:@"name CONTAINS[cd] 'red'"];

NSPredicate *ferraiPred = [NSPredicate predicateWithFormat:@"name CONTAINS[cd] 'ferrari'"];

NSPredicate *compoundPredicate = [NSCompoundPredicate orPredicateWithSubPredicates:[NSArray arrayWithObjects:redPred, ferrariPred, nil]];