Scavo un po 'di più nei framework iOS e ho osservato che il comportamento predefinito della descrizione sdk di iOS non è di collocare "\ n", ma ";".
Esempio:
UIFont *font = [UIFont systemFontOfSize:18];
NSLog(@"FontDescription:%@",[font description]);
NSMutableArray *fontsArray = [NSMutableArray arrayWithCapacity:0];
for(int index = 0; index < 10; index++) {
[fontsArray addObject:font];
}
NSLog(@"FontsArrayDescription:%@",[fontsArray description]);
La put out:
FontDescription: font-family: "Helvetica"; font-weight: normal; stile font: normale; font-size: 18px
FontsArrayDescription :(
"<UICFFont: 0x6e2d8b0> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 18px",
"<UICFFont: 0x6e2d8b0> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 18px",
"<UICFFont: 0x6e2d8b0> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 18px",
"<UICFFont: 0x6e2d8b0> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 18px",
"<UICFFont: 0x6e2d8b0> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 18px",
"<UICFFont: 0x6e2d8b0> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 18px",
"<UICFFont: 0x6e2d8b0> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 18px",
"<UICFFont: 0x6e2d8b0> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 18px",
"<UICFFont: 0x6e2d8b0> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 18px",
"<UICFFont: 0x6e2d8b0> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 18px"
)
Così ho deciso di utilizzare lo stesso approccio con la mia classe.
- (NSString *)description {
NSString *descriptionString = [NSString stringWithFormat:@"Name: %@; Address: %@;", self.name, self.address];
return descriptionString;
}
E put out sarà:
"Nome: Alex; Indirizzo: alcuni indirizzi;"
Per oggetto esso stesso.
objecsArrayDescription :(
"Name:Alex; Address: some address;",
"Name:Alex; Address: some address;",
"Name:Alex; Address: some address;",
"Name:Alex; Address: some address;",
"Name:Alex; Address: some address;",
"Name:Alex; Address: some address;",
"Name:Alex; Address: some address;",
"Name:Alex; Address: some address;",
"Name:Alex; Address: some address;",
"Name:Alex; Address: some address;"
)
Per una matrice di oggetti.
si dovrà ciclo sugli elementi e chiamare 'descrizione' su ciascuno. La descrizione dell'array è l'output formattato, che può cortocircuitare alcune cose come "\ n", per mantenere la formattazione coerente –
vedere [http://stackoverflow.com/a/1828689/971401](http://stackoverflow.com/a/1828689/971.401). Le risposte possono probabilmente aiutarti. –