2009-06-29 9 views

Respuesta

18

Usted puede hacer "búsqueda" de matrices usando predicados, así:

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" 

Usted debe mirar la documentación NSArray y NSPredicate para obtener más información. Si busca información específica para analizar XML (es decir, una fuente RSS), debe consultar el artículo de Matt Gallagher en using libxml2 for XML parsing and XPath queries in Cocoa.

+1

Se han agregado enlaces a la documentación –

+0

shouldnt NSArray * namesStartingWithB = [array filteredArrayUsingPredicate: predicate]; ser NSArray * namesStartingWithB = [nombres filteredArrayUsingPredicate: predicate]; –

+0

@James Gracias por el aviso - arreglado. –

Cuestiones relacionadas