Predicate 谓词不区分大小写

2020-10-21  本文已影响0人  petter102
/**
 Theme: Predicate for Case-Insensitive
 IDE: Xcode 6
 Language: Objective C
 Date: 104/05/12
 Author: HappyMan
 Blog: https://cg2010studio.wordpress.com/
 */
    // 使用predicate來搜尋AND包含name,text,tag
    NSArray *searchArray = [matchText componentsSeparatedByString:@" "];
    NSMutableArray *parr = [NSMutableArray array];
    for (int i = 0; i < [searchArray count]; i++) {
        [parr addObject:[NSPredicate predicateWithFormat:@"(SELF CONTAINS[cd] %@)", searchArray[i]]];
    }
    NSPredicate *thePredicate = [NSCompoundPredicate andPredicateWithSubpredicates:parr];
 
    // 組合text,name,tag
    NSString *compoundStr = [NSString stringWithFormat:@"%@ %@ %@", originalString, senderName, tagName];
    BOOL isMatch = [thePredicate evaluateWithObject:compoundStr];
上一篇下一篇

猜你喜欢

热点阅读