On Oct 27, 2008, at 8:08 PM, Adam Penny wrote:

I am able to write The contents of my one NSTextField to the plist with CFPreferencesSetAppValue, it's writing the two arrays that is the sticking point. When I try to do CFPreferencesSetAppValue for the array(s) I get an EXC_BAD_ACCESS raised by the debugger.

You're trying to store an array of objects of a custom class (Server) to CFPreferences? That won't work.

CFPreferences can only store objects of the Core Foundation property list types. That can include CFArray and CFDictionary, but only if those contain property list typed objects.

If you want to store other types of objects, you have to archive them to/from an NSData/CFData. There's an example here: http://developer.apple.com/documentation/Cocoa/Conceptual/UserDefaults/StoringNSColorInDefaults.html

To use that technique, you'll have to make your Server class conform to NSCoding.


By the way, your Server class -dealloc releases the "name" and "mac" instance variables, but your -init does not retain the initial strings it assigns to them. That's an imbalance. Now, it's not likely that this imbalance will bite you with string literals, but it's still incorrect.

Also, your -toPlist: method makes a copy of the servers array, but it doesn't have to. And your -initWithBundle: will leak the objects obtained from CFPreferences if they aren't of the expected type.

Cheers,
Ken

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to