Hi,
I have a class with a NSMutableArray as readonly property and I need
to execute an action when a new item is added to the array.
I would like:
- to use key-value observing on my NSMutableArray with the collection
accessor pattern
- to preserve the information hiding of my objects and then to change
my current readonly property so that returns a NSMutableArray built
with mutableArrayValueForKey:

The way I've found is the following:
1 - define a private readwrite property with the plain NSMutableArray

NSArray* myPrivateArray;

@interface MyClass ()
@property(nonatomic,retain) NSArray* myPrivateArray;
@end

2 - in the init method initialize the private Array:
...
self.myPrivateArray = [NSMutableArray array];
...

3 - redefine the public readonly property so that return a
NSMutableArray built with mutableArrayValueForKey:

- (NSMutableArray*)myArray {
  return [self mutableArrayValueForKey:@"myPrivateArray"];
}

Such a solution is a good practice?
I could build also the proxy array in the init method, which solution is better?

Thanks.
Giannandrea

-- 
“Keep working, do things in the order that makes more sense and all will be ok.”
_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to