• 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
Problem with bindings and Shared Defaults
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem with bindings and Shared Defaults


  • Subject: Problem with bindings and Shared Defaults
  • From: Duncan Campbell <email@hidden>
  • Date: Tue, 15 Feb 2005 15:05:42 +1100

Sorry for the length of this question - it's necessary to explain my setup:

I'm just getting started with bindings, and thought I had an ok grasp on how things work - but I am having some difficulty getting an NSArrayController to work with Shared Defaults - specifically in saving back the defaults once I add to the array:

My initialize: method looks like so:

// create dictionary for prefs

NSMutableDictionary *defaultValues = [NSMutableDictionary dictionary];


// create default object
myObjectType *myObject = [[myObjectType alloc] init];
[myObject setProperty1:@"Some value"];
[myObject setProperty2:@"Some other value"];


// add default to dictionary
[defaultValues setObject:[NSArray arrayWithObject:myObject] forKey:@"myKey"];


// register the defaults dictionary
[[NSUserDefaults standardUserDefaults] registerDefaults: defaultValues];

In my .nib file, I have an NSArrayController with object class name "myObjectType", with both "property1" and "property2" keys defined. I have an NSTableView bound to this array, with 2 columns - 1 bound to each key.

Back in the NSArrayController, In the bindings contentArray settings I have:

Bind to: Shared User Defaults
Controller Key: values
Model Key Path: myKey

I also have add and remove buttons connected to the add: and remove: methods of the NSArrayController.

Everything works - my NSTableView is populated with the "myKey" array from the prefs, I can edit values, I can delete values - however I cannot add values.

When I run the add: method, my "myObjectType" object is correctly created (I can step thru it's creation and the 2 property settings etc.) it seems to be when this array is then automagically saved back to the Shared Defaults/prefs file that things break and I get the following error:

2005-02-15 14:52:26.486 mojoTime[4010] *** -[NSUserDefaults setObject:forKey:]: Attempt to insert non-property value '<CFArray 0x382200 [0xa01900e0]>{type = mutable-small, count = 2, values = (
0 : <myObjectType: 0x3323a0>
1 : <myObjectType: 0x3818e0>
)}' of class 'NSCFArray'.


Anyone have any ideas?

---------------------------------------------------------------
Duncan Campbell
http://www.duncanandsarah.com/duncan
---------------------------------------------------------------
 _______________________________________________
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: Problem with bindings and Shared Defaults
      • From: mmalcolm crawford <email@hidden>
  • Prev by Date: Re: A few questions about Memory Management
  • Next by Date: Re: Binding userdefaults update
  • Previous by thread: Debugger Expressions Window
  • Next by thread: Re: Problem with bindings and Shared Defaults
  • Index(es):
    • Date
    • Thread