objective c - Conflict between declaring instance variable and property -
i studying objective-c. asked question code earlier came further questions. below code trying make nsarray
externally makes nsmutablearray
internally can add pointers or remove in nsmutablearray
i face 2 questions. 1) purpose of doing this? there specific reason make nsarray
externally? why can't declare property of nsmutablearray
?
2)i learn instance variable (_assets
) made when declare property of nsarray *assets
. , declared nsmutablearray *_assets
under interface. think 2 _assets
conflict each other though have different types. thinking in wrong way?
@interface bnremployee : bnrperson { nsmutablearray *_assets; } @property (nonatomic) unsigned int employeeid; @property (nonatomic) unsigned int officealarmcode; @property (nonatomic) nsdate *hiredate; @property (nonatomic, copy) nsarray *assets;
i'll try put answers way have asked them. let hope clear doubts. guess knowing nsarray
once initialised data wont able add or delete data inside different nsmutablearray
.
the benefit here no 1 else can change externally visible data. when try sort or iterate array sure no other data removed or added. if use nsmutablearray
such cases application crash if add data while iterate array.
like @kirkspaziani explained
@synthesize assets = _assets;
would create instance variable property. supposed use _assets
in getter , setter. else places should using self.assets
.
you can synthesize other array nsmutablearray *_assets
follows
@synthesize _assets = __assets;
have double underscore, frankly shouldn't using underscore starting variable name. plus great if have different names altogether.
also advances in objective c dont require synthesize these variables @ all. use self.variablename
, can access it.
hope clears of queries.
Comments
Post a Comment