• 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: Bug in NSArrayController? (immutable instead of mutable dictionaries)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug in NSArrayController? (immutable instead of mutable dictionaries)


  • Subject: Re: Bug in NSArrayController? (immutable instead of mutable dictionaries)
  • From: "M. Uli Kusterer" <email@hidden>
  • Date: Fri, 22 Oct 2004 04:10:29 +0200

At 3:50 Uhr +0200 22.10.2004, Uli Zappe wrote:
Well, it doesn't in that NSUserDefaultsController does *not* always return immutable objects;

However, it is *documented* as returning immutable objects. That's all the guarantee you get. Mutable objects are a superset of immutable objects, meaning everything an immutable object can do, a mutable object can do as well.

It's like when you buy a piece of wood, and they guarantee you that you'll get at least 2 metres in length and 50cm in width. Just because the last four pieces of wood you bought were actually 2 metres 20cm and 70cm in size it doesn't mean you can rely on that always being the case. They made you a little present, that's all.

In the case of NSUserDefaults, it's probably an internal implementation detail, a performance optimization. Maybe the code they use to load their prefs creates an empty, mutable array and fills it with the objects as it reads from the preferences file. Apple *could* copy this object, but that would be unnecessary duplication. Since an NSMutableArray is a subclass of NSArray, and user defaults are documented to return immutable objects (i.e. an NSArray) even if the object originally stored was mutable, they're violating none of the guarantees they gave you.

So the most important point IMHO is consistency of behavior. If it consistently returns immutable objects, I won't like it, but at least it would be consistent.

The behavior is consistent if you assume the documentation for CFPreferences is right.

Apart from that, wanting to store sets of preferences in an array and in the user defaults system at the same time is such an obvious application for Bindings that it should be possible to do this without all this hassle.

It is. Just treat the array as

If Apple really decides to make immutable the consistent behavior, then at least they should provide a factory NSImmutableToMutableTransformer.

There already is. It's called "mutableCopy".

But IMHO you're going about this the wrong way. You should create the array in your NSArrayController and synchronize it with the prefs, not modify the prefs directly. If you have an intermediate copy, all these problems shouldn't occur. And as I said "handles objects as compound value" may help you get that problem resolved as well.
--
Cheers,
M. Uli Kusterer
------------------------------------------------------------
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Follow-Ups:
    • Re: Bug in NSArrayController? (immutable instead of mutable dictionaries)
      • From: Uli Zappe <email@hidden>
References: 
 >Bug in NSArrayController? (immutable instead of mutable dictionaries) (From: Uli Zappe <email@hidden>)
 >Re: Bug in NSArrayController? (immutable instead of mutable dictionaries) (From: Brent Gulanowski <email@hidden>)
 >Re: Bug in NSArrayController? (immutable instead of mutable dictionaries) (From: Uli Zappe <email@hidden>)
 >Re: Bug in NSArrayController? (immutable instead of mutable dictionaries) (From: Uli Zappe <email@hidden>)
 >Re: Bug in NSArrayController? (immutable instead of mutable dictionaries) (From: Uli Zappe <email@hidden>)
 >Re: Bug in NSArrayController? (immutable instead of mutable dictionaries) (From: "M. Uli Kusterer" <email@hidden>)
 >Re: Bug in NSArrayController? (immutable instead of mutable dictionaries) (From: Uli Zappe <email@hidden>)

  • Prev by Date: Re: confused about framework headers
  • Next by Date: how to force NSSavePanel not to display 'Replace' dialog?
  • Previous by thread: Re: Bug in NSArrayController? (immutable instead of mutable dictionaries)
  • Next by thread: Re: Bug in NSArrayController? (immutable instead of mutable dictionaries)
  • Index(es):
    • Date
    • Thread