|
Saving movie paths in cocoaSoz newbie question. i've got a cocoa app with multiple text fields feeding movie paths into a QC composition i was hoping someone could help me find the best way to save those file path as an external file? or so that when you relaunch my app the text fields will remember the last movie paths used? Thanks for any help Jon
|
Your best bet would probably be to use NSFileManager, with something like this:
"path" is where the file's located, and "text" is an NSString with the data to put in the file. I haven't tried it myself, but I bet you could put an NSDictionary in place of text (remember to cast it to NSData!), and save multiple strings in the file.
you can then read the contents with
contentsAtPath:
, which will return the data stored therein.or you can resort to oldschool posix file o/i, like fopen, fwrite, and fclose. I wouldn't recommend this though.
Chris's suggestion to use NSFileManager is great if you want to store data in a single "configuration file" with a particular name that you specify. If you don't care about the filename and want to let Mac OS X deal with that, you could use the "User Defaults" system, which is really slick --- check out http://developer.apple.com/documentation/Cocoa/Conceptual/UserDefaults/i... . For example, by doing simply:
you get a
~/Library/Preferences/application_identifier.plist
file containing the data you specified. You can read the data just as easily by doing...and this works with any serializable type of data.
However, if you want to have more than a single instance of this data file --- if you want to treat these files as "documents", in that the user can have many of them around and can choose a particular file by double-clicking on it in finder --- you should base your Cocoa application on the NSDocument class. Check out this guide: http://developer.apple.com/documentation/Cocoa/Conceptual/Documents/inde... . Pay close attention to the
readFromData:ofType:error:
anddataOfType:error:
methods.Thanks guys for the point in the right direction, sounds like a fun week of cocoa down time for me