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, since lbl_lastname nil, fails.
  • the nslog correctly prints out fact lbl_lastname.text ni, since have 2 %@, prints out next object in memory. happens string: @"xlast" allocated.

this undefined behaviour , may not act same every time.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -