Re: CFPreferences and init.
Re: CFPreferences and init.
- Subject: Re: CFPreferences and init.
- From: Adam Penny <email@hidden>
- Date: Sun, 26 Oct 2008 13:02:06 +0100
Hi there,
Thanks for your response Kyle.
Based on that I did this in my -(id)initWithBundle method and tested
it with and without a PList in the right place and it works:
servers= [[NSMutableArray alloc] init];
CFPropertyListRef
serversFromPlist=CFPreferencesCopyAppValue( CFSTR("servers"), appID);
if (serversFromPlist &&
CFGetTypeID(serversFromPlist)==CFArrayGetTypeID())
{
[servers addObjectsFromArray: serversFromPlist];
// Get warning here: passing argument 1 of addObjectsFromArray
ignores qualifiers from target
}
printers= (NSMutableArray *)
CFPreferencesCopyAppValue( CFSTR("printers"), appID);
I think that the if clause protects the program from getting the wrong
pointer types, but I don't feel right about letting this ride with a
warning in it. Opinions?
Thanks,
Adam
On Oct26, 2008, at 12:39 AM, Kyle Sluder wrote:
On Sat, Oct 25, 2008 at 6:11 PM, Adam Penny <email@hidden>
wrote:
My question is how do I do the checks for the if clause?
The documentation says that if the key doesn't exist, the function
returns NULL. So then you just check to see if your servers variable
is null. The documentation also mentions using CFGetTypeID to
determine if a CFPropertyListRef is an array or some other type. And
NSMutableArray is toll-free bridged to CFMutableArrayRef. So:
servers = CFPreferencesCopyAppValue( CFSTR("servers"), appID);
if(servers && CFGetTypeID(servers) == CFArrayGetTypeID())
{
// woohoo!
}
--Kyle Sluder
_______________________________________________
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