Ich kann keinen Weg finden, um die n th Element in einem Array mit einem NSPredicate
String. Zum Beispiel:NSPredicate String, um n-tes Element im Array zu erhalten
//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;
}
Gibt es einen Grund, warum Sie ein Prädikat Zeichenfolge verwenden möchten und nicht nur 'Array [indexYouWant] 'oder' [array objectAtIndex: indexYouWant] '? – AdamPro13
Ja für was ich tun, ich habe keinen Verweis auf das Array selbst, ich kann nur mit NSPredicateString abfragen. Ich bekomme in diesem Fall nur das gefilterte Array zurück. – Rafthecalf
Sie können dieses Array in einem temporären Array speichern und 'objectAtIndex' verwenden, um das n-te Element zu erhalten. – Lion