Reputation:
I am trying to learn how to read and write data from a plist file, using cocoa on OS X.
I've look around but I see a lot of examples for iOS; and I assume that even if the 2 cocoa frameworks are about the same, you do it in a different way on OS X, compared to iOS.
Is there any place where I can get a tutorial about how to read and write data from/to a plist in Cocoa?
Upvotes: 2
Views: 1998
Reputation: 7720
You do it exactly the same way (minus getting the actual file, but as far as I understand that's not the question being asked).
If you want to read a plist file you use [NSArray arrayWithContentsOfURL:]
or [NSArray arrayWithContentsOfFile:]
or the respective methods on NSDictionary
If you are writing to a plist you just use [NSArray/NSDictionary writeToFile:atomically:]
edited to add info from Catfish_Man's comment:
The above works for plists where the root object is either an array or a dictionary. For other root objects have a look at NSPropertyListSerialization
Upvotes: 5