有一個NSArray,我想用predicate過濾一下。
NSLog(@"text is %@",txtSearch.text);
NSPredicate *bPredicate =
[NSPredicate predicateWithFormat:@"SELF beginswith[c] '%@'",txtSearch.text];
arrSearchedPlayers =
[arrPlayers filteredArrayUsingPredicate:bPredicate];
NSLog(@"array after searched is %@",arrSearchedPlayers);
但是再輸入文本時數組還是空的,使用下面的predicate的話就結果正常:
NSPredicate *bPredicate =
[NSPredicate predicateWithFormat:@"SELF beginswith[c] 's'"];
這是為什麼呢?
NSPredicate *bPredicate =[NSPredicate predicateWithFormat:@"SELF beginswith[cd] %@",txtSearch.text];