• 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
Re: NSDictionary allValues not mutable
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSDictionary allValues not mutable


  • Subject: Re: NSDictionary allValues not mutable
  • From: Greg Guerin <email@hidden>
  • Date: Mon, 18 Oct 2010 10:50:40 -0700

Trygve Inda wrote:

Or does NSArrayController somehow bind to a non-array property, but one
that responds as if it were an array?


Later in my original post, I suggested subclassing NSMutableArray, so it can bind to NSArrayController. Your new class, i.e. MyDataClass, doesn't just respond *as if* it were an array, it *is* an actual subclass of NSMutableArray, albeit a specialized one. The visible relationship between MyDataClass and NSMutableArray is *is-a*, not *has-a*.

Internally, MyDataClass keeps both an NSMutableArray (to provide the array behavior), and an NSMutableDictionary for fast searching. You need to override the minimal methods of any NSMutableArray subclass, so it essentially forwards to the internal array. You also override the add/remove methods so objects are added/removed from both the internal array and the internal dictionay. You then override any of the find or search methods to use the internal dictionary. Or you can add new methods that perform this fast search, and call those when you need fast search as distinct from linear search (a formal protocol is optional).

If you have a singleton class whose method you bind to, it could be declared as returning NSMutableArray, but it would actually return an instance of MyDataClass, i.e. your search-enhanced subclass of NSMutableArray. In other words, you arrange the classes and bindings so NSArrayController gets an instance of your specialized data- container, instead of an instance of a generic array container.

The singleton whose method you bind to can be another class, or it can be an instance of MyDataClass itself. In the latter case, the binded method simply returns self.

  -- GG

_______________________________________________

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


  • Prev by Date: NSOperation completionBlock not executed
  • Next by Date: Re: NSDictionary allValues not mutable
  • Previous by thread: Re: NSDictionary allValues not mutable
  • Next by thread: Re: NSDictionary allValues not mutable
  • Index(es):
    • Date
    • Thread