Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective C - Writing an NSString to a plist

I'm writing an NSString to a plist file but after its written to the plist, and when I try to open i get the following message "This document "mylist.plist" could not be opened XML parser error: Unexpected character 2 at line 1 Old-style plist parser error: Unexpected';' or '=' after key at line 1"

Here is my code:

NSString *temp = [NSString stringWithFormat:@"%@\n Selection is %@ \n %d for %.2lf = %.2lf", [NSDate date], @"IPC", 2, 42.34, 2 * 42.34]; 
[temp writeToFile:[self getPathName:@"mylist.plist"] atomically:YES]; 

any help would be appreciated.

Thanks,

like image 311
Timothy Avatar asked Dec 21 '25 04:12

Timothy


1 Answers

-[NSString writeToFile...] does not create a plist. It creates a text file. There is no such thing as "writing a string to a plist". Only NSArray and NSDictionary objects can be written to plist files. Those can then contain NSString objects (and other objects, like NSDate and NSData, etc), but what you're asking for is not possible.

For more information, check out the Property List Programming Guide.

Edit: I should clarify what I mean by "creating a plist". When I say that, I'm referring to the XML documents defined by the Apple Plist DTD: http://www.apple.com/DTDs/PropertyList-1.0.dtd

like image 123
Dave DeLong Avatar answered Dec 22 '25 18:12

Dave DeLong



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!