美文网首页
Predicate 谓词不区分大小写

Predicate 谓词不区分大小写

作者: petter102 | 来源:发表于2020-10-21 15:50 被阅读0次
    /**
     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];
    

    相关文章

      网友评论

          本文标题:Predicate 谓词不区分大小写

          本文链接:https://www.haomeiwen.com/subject/ezhemktx.html