Hi again,

I got the CFPreferences synchronize app working but, I'm now having issues with CFPreferencesSetApp value for an array.

This is my code for the method in question and it's used for the NSTableView bindings:
- (void) setServers:(NSMutableArray *)a;
{
        //Method for adding a new server, with mac address to the servers array
        if (a==servers) return;
        [a retain];
        [servers release];
        servers = a;
        NSArray *serversToCopy = [servers copy];
//Next line causes an exception when adding a row.
if ([servers count]!=0) CFPreferencesSetAppValue(CFSTR("servers"), (NSArray *)serversToCopy, appID);
        else CFPreferencesSetAppValue(CFSTR("servers"), NULL, appID);
        else NSLog(@"It's zero!");
        [self updatePrefs];
        
}


It's building fine, but when I ran it I found that when I remove a row from the table then it will remove the row from the plist happily and without fuss. However, if I try to add a new row then I get an exception, EXC_BAD_EXCESS. I thought that maybe it was something to do with special characters in my array, but I tried removing them from the default values and no joy.

The other thing that's confusing me is that what was an XML Plist that I did by hand like this:
<key>servers</key>
<array>
<key>sname</key>
<string>PennyG5.local</string>
<key>mac</key>
<string>00:00:00:00:00:00</string>
</array>
etc...

has been transformed by the synchronization to this(!):


bplist00Ó[broadcastIPWserversXprinters]192.168.1.254¡Ò TnameSmac^PennyMBP.local_00:1b:63:c4:aa:1c¢ Ó VserverSuri_&Brother_HL_1650_1670N_series___PennyG5_Gmdns://Brother %20HL-1650_1670N%20series%20%40%20PennyG5._ipp._tcp.localÓ _EPSON_AL_C900___PennyG5]PennyG5.local_6mdns://EPSON%20AL- C900%20%40%20PennyG5._ipp._tcp.local#,:<AFJYmpw~‚«õü$]

I keep on rereading the documentation and scouting around for examples, but this class really is getting the better of me. Help!

Adam







On Oct26, 2008, at 1:12 PM, Jean-Daniel Dupas wrote:


Le 26 oct. 08 à 13:02, Adam Penny a écrit :

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?


So, tell the compiler that this is an NSArray:

        [servers addObjectsFromArray: (NSArray *)serversFromPlist];



Ahhhhh, thank you!

Adam

_______________________________________________

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/adam %40pennynet.co.uk

This email sent to [EMAIL PROTECTED]

_______________________________________________

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/adam%40pennynet.co.uk

This email sent to [EMAIL PROTECTED]

_______________________________________________

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