objective-c Add to/Edit .plist file
Posted
by Dave
on Stack Overflow
See other posts from Stack Overflow
or by Dave
Published on 2010-03-12T02:28:40Z
Indexed on
2010/03/12
2:57 UTC
Read the original article
Hit count: 444
Does writeToFile:atomically, add data to an existing .plist? Is it possible to modify a value in a .plist ? SHould the app be recompiled to take effect the change?
I have a custom .plist list in my app. The structure is as below:
<array>
<dict>
<key>Title</key>
<string>MyTitle</string>
<key>Measurement</key>
<dict>
<key>prop1</key>
<real>28.86392</real>
<key>prop2</key>
<real>75.12451</real>
</dict>
<key>Distance</key>
<dict>
<key>prop3</key>
<real>37.49229</real>
<key>prop4</key>
<real>58.64502</real>
</dict>
</dict>
</array>
The array tag holds multiple items with same structure. I need to add items to the existing .plist. Is that possible? I can write a UIView to do just that, if so.
*EDIT - OK, I just tried to writetofile hoping it would atleast overwrite if not add to it. Strangely, the following code selects different path while reading and writing.
NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
The .plist file is in my project. I can read from it. When I write to it, it is creating a .plist file and saving it in my /users/.../library/! Does this make sense to anyone?
© Stack Overflow or respective owner