2009-06-29 4 views

Répondre

18

Vous pouvez faire « rechercher » des tableaux en utilisant prédicats, comme ceci:

NSMutableArray* names = [NSMutableArray arrayWithObjects:@"Andy", @"Bart", @"Bob", nil]; 
NSPredicate* predicate = [NSPredicate predicateWithFormat:@"SELF beginswith[c] 'b'"]; 
NSArray* namesStartingWithB = [names filteredArrayUsingPredicate: predicate]; 
// namesStartingWithB now contains @"Bart" & @"Bob" 

Vous devriez regarder la documentation NSArray et NSPredicate pour plus information. Si vous recherchez des informations spécifiques à l'analyse XML (c'est-à-dire un flux RSS), vous devriez consulter l'article de Matt Gallagher au using libxml2 for XML parsing and XPath queries in Cocoa.

+1

Liens de documentation ajoutés –

+0

should not NSArray * namesStartingWithB = [array filteredArrayUsingPredicate: predicate]; être NSArray * namesStartingWithB = [names filteredArrayUsingPredicate: predicate]; –

+0

@James Merci pour la tête - fixe. –

Questions connexes