iphone - When we need Pointer of BOOL Variable in Objective C? -


in case need pointer of bool variable in objective c language?

i have code collapsible uitableview in there function declaration:

- (void)toggle:(bool*)isexpanded section:(nsinteger)section;  

and definition is:

- (void)toggle:(bool*)isexpanded section:(nsinteger)section  {     *isexpanded = !*isexpanded;      nsarray *paths = [self indexpathsinsection:section];      if (!*isexpanded)     {         [self.tableview deleterowsatindexpaths:paths withrowanimation:uitableviewrowanimationfade];     }     else      {         [self.tableview insertrowsatindexpaths:paths withrowanimation:uitableviewrowanimationfade];     } 

*isexpanded = !*isexpanded; meaning of statement have never used kind of statement in case of bool variable.

following other 2 functions of same code called in sequence of above function:

- (nsarray*)indexpathsinsection:(nsinteger)section  {     nsmutablearray *paths = [nsmutablearray array]; nsinteger row;     ( row = 0; row < [self numberofrowsinsection:section]; row++ )      {         [paths addobject:[nsindexpath indexpathforrow:row insection:section]];     }     return [nsarray arraywitharray:paths]; }  - (nsinteger)numberofrowsinsection:(nsinteger)section  {     return [[sectiondataarray objectatindex:section] count]; } 

sectiondataarray array number of rows in each section. may unclear if got point please explain this.

here link code

thanks

pointers variables (or pointer pointers of objects) useful, if want change value in function. if pass plain bool method, can use it, if change it, change local passed value. if pass pointer/address of variable instead, can change real value.

this comes in handy if need more 1 return value , don't want wrap in object. it's common pattern in cocoa nserror variables passed pointers, i.e -(bool) dosomethingerror:(nserror **)error.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -