您好我正在使用NSPredicate来搜索5个元素阵列的NSArrays对象,然后返回结果。但有没有办法得到NSPredicate返回的匹配结果以及匹配成功的字符串(在5个元素数组中)?
答案 0 :(得分:1)
尝试这样,
这个谓词给出了不包含该子串的数组。
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"not SELF contains '%@'",searchString];
NSArray *array = [NSArray arrayWithObjects:@" AhfjA ", @"test1", @"best", @"AntA", nil];
NSArray *filteredArray = [array filteredArrayUsingPredicate:predicate ];
NSLog(@"%@",filteredArray );
O / P: -
(
AhfjA,
best,
AntA
)
它给出了包含子串
的数组 NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF contains '%@'",searchString];
NSArray *array = [NSArray arrayWithObjects:@" AhfjA ", @"test1", @"best", @"AntA", nil];
NSArray *filteredArray = [array filteredArrayUsingPredicate:predicate ];
NSLog(@"%@",filteredArray );
O / P: -
(
test1,
)