• 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
Re: CFPreferences and init: a possible reason?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >CFPreferences and init. (From: Adam Penny <email@hidden>)
 >Re: CFPreferences and init. (From: Adam Penny <email@hidden>)
 >Re: CFPreferences and init. (From: Jean-Daniel Dupas <email@hidden>)
 >Re: CFPreferences and init. (From: Adam Penny <email@hidden>)
 >Re: CFPreferences and init. (From: Adam Penny <email@hidden>)
 >Re: CFPreferences and init. (From: Adam Penny <email@hidden>)
 >Re: CFPreferences and init. (From: "Kyle Sluder" <email@hidden>)
 >Re: CFPreferences and init. (From: "Kyle Sluder" <email@hidden>)
 >Re: CFPreferences and init. (From: "Adam R. Maxwell" <email@hidden>)
 >Re: CFPreferences and init. (From: "Kyle Sluder" <email@hidden>)
 >CFPreferences and init: a possible reason? (From: Adam Penny <email@hidden>)

  • Prev by Date: If the NIB instantiates everything how does the controller get a reference to the View and the Model?
  • Next by Date: Re: If the NIB instantiates everything how does the controller get a reference to the View and the Model?
  • Previous by thread: CFPreferences and init: a possible reason?
  • Next by thread: Re: CFPreferences and init.
  • Index(es):
    • Date
    • Thread