objective c - NSLog prints a string different to the NSString with format -


this i'm baffled by: when initialize string format 2 different variables this

order *o = [orders objectatindex:i]; nsstring *line = [[nsstring alloc] initwithformat:(@"%@;%@\n", [o _length], [o _amount])]; 

and print out

nslog(@"%@", line); 

it shows this:

tableviewtest[4812:123250] 200 

which wrong. if same doing this

nslog(@"%@;%@\n", [o _length], [o _amount]); 

it comes out this:

tableviewtest[4812:123250] 120cm;200 

which how i'd want line be. why happening? need in same format line can write text file later.

edit:

_length , _amount @property nsstring *_length in order-class. orders nsmutablearray houses data nstableview, data put in nscomboboxes , nstextfields. compiler gives warning: format string not string literal (potentially insecure).

instead of
nsstring *line = [[nsstring alloc] initwithformat:(@"%@;%@\n", [o _length], [o _amount])];,
use
nsstring *line = [nsstring stringwithformat:@"%@;%@\n", [o _length], [o _amount]];


Comments