Tengo el siguiente código:
NSString *str = @"David Likes Going To The Park";
NSString *separator = @" ";
NSArray *strSplit = [str componentsSeparatedByString:separator];
NSNumber *strSplitLength = [NSNumber numberWithInteger:[strSplit count]];
NSLog(@"Splitting STRING %@ on SEPARATOR %@ = %@ of LENGTH %@", str, separator, strSplit, strSplitLength);
¿Sería este código considerado aceptable? O si todas las variables se definen en la parte superior antes del uso, algo como:
NSString *str, *separator;
NSNumber *strSplitLength;
NSArray *strSplit;
// rest of code
Respuestas
0 para la respuesta № 1En la primera parte hiciste "declaration cum definition
"en la segunda parte aplazó la definición.
La memoria para el objeto se creará una vez que lo defina. Así que no hay diferencia.