Re: controller example works in IB but not in app
Re: controller example works in IB but not in app
- Subject: Re: controller example works in IB but not in app
- From: Scott Anguish <email@hidden>
- Date: Thu, 22 Apr 2004 20:17:08 -0400
it works in IB because IB isn't really writing them out to the defaults
if you're app is set so that it erases the defaults each time it runs
(I believe the default is to erase the defaults when quitting IB, but I
may have changed it). It writes them to the defaults, but it never
needs to read them from the persistent storage, it's already in memory.
So, technically it's a bug that it does work in IB. it's also a bug
(well, weakness worth enhancing) that it doesn't work with immutable
items with NSUserDefaultsController.
it's a bigger bug that it doesn't work the way you'd expect outside of
IB, and that'd be the better fix. :-)
On Apr 22, 2004, at 8:01 PM, matt neuburg wrote:
Here's a simple setup with controllers that works in IB but chokes in
the
built app, and I'm trying to understand why. I'm sure there's a simple
reason... It may well have been explained here before, so forgive me
for not
finding the explanation. This is almost (or perhaps exactly) the same
as:
<http://cocoa.mamasam.com/MACOSXDEV/2004/02/2/84555.php>
But I didn't understand mmalc's answer there, as we shall see.
Work in IB. Make a table with one column, in a window. Make an
NSArrayController. Bind the table column's value to the
NSArrayController's
arrangedObjects.thing (or whatever name suits you).
Now let's add an Add button. So, make the button in the window, and
make its
action be the NSArrayController's add: method.
Now bind the NSArrayController's contentArray to Shared User Defaults,
values.stuff (or whatever name you like).
Run the interface within IB. It works great. You can add rows, you can
edit
them, and they are remembered between runs. Cool!
Now go to Xcode and build-and-run the app. You can add a row, but when
you
try to edit it and hit Tab to set the edit, you get an exception.
-[NSCFDictionary setObject:forKey:]: mutating method sent to immutable
object
mmalc says, both in the above thread and at his site, "collections
retrieved
from user defaults are immutable, so if you're storing lists in user
defaults you may have to create mutable copies before you can modify
them".
And he gives some code for modifying the binding for an object to
insert a
data transformer that does this. But what I really don't get is: if I'm
doing it wrong, then why does it work so perfectly in IB? Is that a
bug? Thx
- m.
--
matt neuburg, phd = email@hidden, http://www.tidbits.com/matt/
pantes anthropoi tou eidenai oregontai phusei
AppleScript: the Definitive Guide! NOW SHIPPING...! (Finally.)
http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt
Subscribe to TidBITS! It's free and smart. http://www.tidbits.com/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.