Re: CFPreferences and init: a possible reason?
Re: CFPreferences and init: a possible reason?
- Subject: Re: CFPreferences and init: a possible reason?
- From: Ken Thomases <email@hidden>
- Date: Mon, 27 Oct 2008 20:55:56 -0500
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 (email@hidden)
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:
This email sent to email@hidden