Re: editing plist file
Re: editing plist file
- Subject: Re: editing plist file
- From: Chris Suter <email@hidden>
- Date: Wed, 24 May 2006 16:54:02 +1000
On 24/05/2006, at 4:43 PM, Renato Maschion wrote:
I have been reading the post about changing plist using
NSMutableDictionary and I'm "almost" there.
I'm able to read a plist and search for certain keys and add or
modify its contents.
I'm using for add/modify a key:
[myDict objectForKey:@"KEY1"] setValue: myArray forKey:@"ITEM1"];
where myArray is a NSArray with two items.
this is what I expect on my plist
<?xml version...>
<!DOCTYPE plist...>
<plist version="1.0")
<dict>
<key>KEY1</key>
<dict>
<key>ITEM1</key>
<array>
<integer>0</integer>
<true/>
</array>
<key>KEY2....
....
My problem now is how to add a new keys to the Root if they don't
exist.
For example, if KEY1 doesn't exist I don't know how to create a new
<dict> key.
I understand that key1 is a dict and must have a different syntax
but I'm not finding.
The top level type of a property list depends upon what type you use
for the property list. If you use NSMutableDictionary, the root will
always be dict, but there's nothing stopping you using an
NSMutableArray an NSString, or any of the other valid property list
types.
When reading a property list in, you might want to check that it's a
dictionary you're dealing with.
setObject:forKey will add a new key if the key doesn't already exist.
Also, since we are talking about NSMutableDictionary: the plist I'm
reading is in binary format. I can read with initWithContentsOfFile
without problems. But when I save using
writeToFile: atomically: YES it saves as xml.
Is there a way to save as binary again?
Use NSPropertyListSerialization
tks for helping...
renato
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden