2011-12-06 4 views

Respuesta

18

vamos a encontrar la manera más compleja, deberá ¿nosotros?

NSArray *myArray = [NSArray array]; 
id *objects = malloc(sizeof(id) * myArray.count); 
[myArray getObjects:objects range:NSMakeRange(0, myArray.count)]; 

char **strings = malloc(sizeof(char *) * myArray.count); 

for (int i = 0; i < myArray.count; i++) 
{ 
    strings[i] = [objects[i] UTF8String]; 
} 

printf("<"); 
for (int i = 0; i < myArray.count; i++) 
{ 
    printf("%s" strings[i]); 
    if (i != myArray.count - 1) 
     printf(", "); 
} 
printf(">"); 

free(objects); 
free(strings); 

Por supuesto, siempre puedes hacerlo de esta manera:

NSLog(@"%@", myArray); 
+1

Gracias. lo tomo: – Xtrician

+10

¿Cómo fue esto aceptado? Solo estaba siendo un hombre inteligente –

+2

bastante impresionante. Me falta algo de cambio de bit ... – vikingosegundo

25

La forma más sencilla es simplemente:

NSLog(@"%@", myArray); 

O, si desea utilizar la enumeración rápida para imprimir cada objeto en su propia manera:

for (NSString *string in myArray) { 
    NSLog(@"%@", string); 
} 
Cuestiones relacionadas