• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Use of mutableArrayValueForKey
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Use of mutableArrayValueForKey


  • Subject: Use of mutableArrayValueForKey
  • From: Giannandrea Castaldi <email@hidden>
  • Date: Fri, 17 Dec 2010 10:42:30 +0100

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@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Use of mutableArrayValueForKey
      • From: Ken Thomases <email@hidden>
  • Prev by Date: Re: App Will Not Terminate After Uncaught Excpetion
  • Next by Date: Re: Image conversion to RGBA colors
  • Previous by thread: Re: File name issue with German umlauts
  • Next by thread: Re: Use of mutableArrayValueForKey
  • Index(es):
    • Date
    • Thread