The best way to save an array of objects in an iPhone application.

I have a program for iPhone with a table view. The table view displays its data from an NSMutable Array. I want people to be able to add data to this table, that is, add objects to this array. Using addObject and reloadData , I can add objects to the array and reload the table view so that the newly added data is also displayed. However, as soon as I started the application again, there was no new data. My question is the best way to save an array on iPhone so that when I restart it, I can populate the table with user-added data?

thanks

+4
source share
1 answer

I think these are your options.

1) NSUserDefaults

If you want to store only one information about the array, you can use NSUserDefaults one of the easiest ways to store data. Good tutorial here .

PS: Never use NSUserDefault to store sensitive information as login credentials. To do this, use the KeyChain services . A simple tutorial explaining the use here .

2) Basic data

If you have a large dataset and are looking for a database style repository, you should look at the basic data. Master Data is a high-level API written over lower SQLite concepts and very good. Good tutorial here and here

3) SQLite

If you want to use the database using the old-fashioned way (of writing queries), you can use sqlite directly on the iPhone. You can get good information from here , here and from this SO question .

+12
source

Source: https://habr.com/ru/post/1345308/


All Articles