如果我想在字符串中找到“color”这个词“红色是我蜡笔盒中的颜色”,我该如何构建它?
谢谢,
答案 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]];