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

Bug in NSArrayController? (immutable instead of mutable dictionaries)


  • Subject: Bug in NSArrayController? (immutable instead of mutable dictionaries)
  • From: Uli Zappe <email@hidden>
  • Date: Thu, 21 Oct 2004 23:50:02 +0200

Hi,

is anybody here aware of the following bug in NSArrayController? In view of all the talk about Bindings, I can't imagine nobody has encountered it, but on the other hand, I haven't found anything about it in this mailing list and the other usual sources.


In the following code, arrayController is an IBOutlet that's connected to an instance of NSArrayController in Interface Builder. If you print [arrayController content] in the debugger before you do anything with arrayController, you get:

<CFArray 0x55e2e0 [0xa01900e0]>{type = mutable-small, count = 0, values = (
)}

i.e. its initial content array is an empty mutable array, which is what you would expect (the NSArrayController instance is set to be editable in the Interface Builder's Attribute Info window).

Also in the Interface Builder's Attribute Info window, the Object Class Name of the NSArrayController instance is set to NSMutableDictionary, the default.

In the code, [arrayController objectClass] returns NSMutableDictionary as well, so NSMutableDictionary is definitely set as the object class.

According to the documentation, in this case [arrayController insert:self] is supposed to add a new NSMutableDictionary to the controller's content array. However, if, after this message call, you print [arrayController content] in the debugger, you get:

<CFArray 0x5bbb00 [0xa01900e0]>{type = immutable, count = 1, values = (
0 : <CFDictionary 0x52d960 [0xa01900e0]>{type = immutable, count = 0, capacity = 0, pairs = (
)}
)}

In other words, instead of a mutable dictionary, an *immutable* dictionary is added. What's more, the content array, which was mutable before, has also become immutable.

This is even the case if you use

[arrayController insertObject:[[[NSMutableDictionary alloc] init] autorelease] atArrangedObjectIndex:0];

i.e. although you explicitly send a message to add a mutable dictionary, an immutable dictionary is added. Other methods, such as addObject:, lead to the same result.

Even worse, if the content array already contained one or more mutable dictionaries before [arrayController insert:self] (or one of the respective other messages), they *all* will become immutable after the message call (their key/value pairs remain the same).

The *only* way that I found to add a mutable dictionary to the content array that will remain mutable is to add it to the content array directly:

[[arrayController content] addObject:[[[NSMutableDictionary alloc] init] autorelease]];

But then arrayController is unaware of the change, and no bound objects will be updated. So you can't actually use this method, either.

This has fatal consequences, because as a result no bound control view will ever be able to update one of arrayController's content array's dictionaries with its value; instead, you'll always get the following error:

-[NSCFDictionary setObject:forKey:]: mutating method sent to immutable object

which is hardly surprising given that the dictionary has become immutable.


So, am I overlooking the obvious, or is this the bug I think it is, and for whatever reason nobody has encountered it so far?


Bye
Uli
________________________________________________________

Uli Zappe, Solmsstraße 5, D-65189 Wiesbaden, Germany
http://www.ritual.org
Fon: +49-700-ULIZAPPE
Fax: +49-700-ZAPPEFAX
________________________________________________________
_______________________________________________
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: Scott Stevenson <email@hidden>
    • Re: Bug in NSArrayController? (immutable instead of mutable dictionaries)
      • From: Brent Gulanowski <email@hidden>
  • Prev by Date: Re: Toolbar Item Validation in a Panel
  • Next by Date: Re: Copy and release
  • Previous by thread: Re: Tall NSTableView Column Headers
  • Next by thread: Re: Bug in NSArrayController? (immutable instead of mutable dictionaries)
  • Index(es):
    • Date
    • Thread