ios - Why NSLog print like these? -
line of code:
@interface viewcontroller (){ iboutlet uilabel *lbl_firstname; iboutlet uilabel *lbl_lastname; } @implementation viewcontroller - (void)viewdidload { [super viewdidload]; lbl_firstname.text=@"xfirst"; lbl_lastname.text=@"xlast"; nslog(@"first name: %@",lbl_firstname.text); nslog(@"last name: %@ %@",lbl_lastname.text); } result:
first name: xfirst last name: (null) xlast problem: * why 2nd nslog statement print these?
i know reason of (null), because didn't give reference lbl_lastname in .xib. don't know reason of print after (null).
it appears next object in memory happens value of "xlast".
what speculate happens is:
- you create string:
@"xlast" - the program attempts assign value
lbl_lastname.text, sincelbl_lastnamenil, fails. - the nslog correctly prints out fact
lbl_lastname.textni, since have 2%@, prints out next object in memory. happens string:@"xlast"allocated.
this undefined behaviour , may not act same every time.
Comments
Post a Comment