NSMutableArray *_assets and (NSArray *)a


#1

[quote=“Cdub2235”]Hi all,

I know this has been asked a few times in this board but I want to clarify a few things.

Interface :

//Create an Ivar to hold a pointer to the mutable array of assets. { NSMutableArray *_assets; }

Implementation:

-(void)setAssets:(NSArray *)a
{
    _assets = [a mutableCopy];
}

- (NSArray *)getAssets
{
    return [_assets copy];
}

So in the interface or header file we declare a ivar of type NSMutableArray that will hold the address to a NSMutableArray.

In the implementation we modify the setter and getter method for the

-(void)setAssets:(NSArray *)a { _assets = [a mutableCopy]; }; this makes a mutable copy of the immutable assets that was declared in the property and assigns it to the ivar that holds the pointer to a NSMutableArray Object

I’m not exactly sure what this does.

- (NSArray *)getAssets { return [_assets copy]; }

but this is my guess:
Returns a copy of the pointer _assets to a NSMutableArray, but…since we used copy here the getter method will return a immutable NSArray?

Another question, since we created the ivar NSMutableArray *_assets in BNREmployee.h we will only be able to modify the array with a BNREmployee object right?

Can someone please comment and tell me if my statements are (true or false and please elaborate and correct me if I’m wrong, which I think I am :smiley: )

Thanks![/quote]

Hi, several days ago I’ve the same doubt.
Can someone help me?
Thanks!