houbysoft
houbysoft

Reputation: 33402

iPhone local storage -- Core Data, NSFileManager, ...?

I am making a simple iPhone app that will basically be an editor.

As such, I need some way to store the documents the user creates.

Since on iPhone, the concept of the filesystem is not present for the user, I searched around to see what I should use.

I found this question & answer that basically says to use Core Data, but I recently found out about NSFileManager.

My question simply is, for user-created documents, what is the best storage system to use? Traditional files by using NSFileManager? Core Data? Something else?

Upvotes: 0

Views: 836

Answers (2)

borrrden
borrrden

Reputation: 33421

If all of your data for displaying the file is contained in one long string (like HTML) then I would recommend that you use the file manager, since it will be easy to get a list of files in a certain directory to display to the user for opening. However, if they are not self contained (like NSAttributedString, which has many stored formatting regions along with the actual content) then you should use CoreData, as it will be easier to keep all the pieces together.

Upvotes: 0

sosborn
sosborn

Reputation: 14694

Personally, I would use CoreData because it will abstract away all of the file-management code for you. If you are making simple text documents then this isn't such a big deal, but if you are working with a complex document architecture (i.e., a collection a numerous objects) then it can save you a lot of effort.

If the user wants to export their document it is very easy to write a function to do so with your CoreData objects.

The only downside to CoreData is that if you are using non-standard attributes it can get a little bit tricky, but it is certainly not a deal breaker in most cases.

People create document formats without CoreData all of the time, so there are plenty of examples out there, and it will just come down to personal preference. There really isn't any generalized right answer to this - it a design decision that should be evaluated on a per-app basis.

Upvotes: 2

Related Questions