Alex Rivera | Logout

What are the options for saving data in iOS?

Asked 2010-11-02T05:09:47.547
21

I'd like to serialize a bunch of data and save it to a file, then be able to load it (naturally) and play it back with a feature I have written. (Sorry if my terminology is off, I am a novice with this sort of thing.) What is the best way to do this with iOS? From looking at documentation here:

Standard Application Behaviors Guide

I've gathered that I should use NSSearchPathForDirectoriesInDomains for finding the appropriate storage directory root (Documents?) and then use NSData to store these data buffers I create and write them to file. Am I spot on with that or have I got it wrong? Any other sage advice?

Edit
Report

1 Answer

14

It depends on the data you are writing. If you mostly want to serialize objects, see the NSCoding protocol. If you have some simple data structure that’s not a class, you can store that into a NSDictionary and save it into a plist. And if you have a big chunk of data (like thousands of floats or something like that), you might want to save that using NSData as you already hinted. In any case be sure to read the Archives and Serializations Programming Guide so that you don’t reinvent the wheel.

answered 2010-11-02T07:36:14.840

Your Answer