我找不到一种方法使用NSPredicate
字符串获取数组中的第012项项目中的第个项目。例如:NSPredicate String获得第n个项目
//You cannot touch or modify the code inside this method. You can only use the predicate string param to filter the array.
- (NSArray *)filterUsingNSPredicate:(NSString *)PredicateString
{
NSArray *array = @[
@"firstItem",
@"secondItem",
@"thirdItem",
@"fourthItem",
];
NSPredicate *pred = [NSPredicate predicateWithFormat:PredicateString];
NSArray *filtered = [array filteredArrayUsingPredicate:pred];
NSLog(@"This is the second item in the array! %@",filtered); //Thats the only thing in the array.
return filtered;
}
有没有您想要使用的谓词字符串,而不只是'阵列的理由[indexYouWant]'或'[array objectAtIndex:indexYouWant]'? – AdamPro13
是的,我在做什么,我没有对数组本身的引用,我只能使用NSPredicateString进行查询。在这种情况下,我只是将过滤后的数组返回给我。 – Rafthecalf
您可以将该数组存储在临时数组中并使用'objectAtIndex'获取第n个元素 – Lion