Search code examples
iosswiftstore

Best method to store data for an iOS app?


I would like to develop a stock/item inventory app as I progress through learning swift. It would basically be something that has, Item Name, Quantity, and Location.

eg.

Lightbulbs, 25, Work Van

Switches, 6, Warehouse

When the user inputs this data and presses a button, whats the best method of storing this data and retrieving it later. I know I could append this to an array and display the array, but what if the app closes?

Should I be looking at learning database storage? Can I save data to the phone?


Solution

  • If the data you want to store is very little and not sensitive, you can use UserDefaults For example, user's name, their age etc.

    For Large amounts of data you should use Core Data, its a good and an easy way to manage your objects. For example, you have 1000 items, each with a property, you can basically use core data for that. It is pretty straightforward as how to create Managed Objects, store them and how to later retrieve them using queries.

    Basically when you configure your project with core data, project creates an sqlite file attached to your project.

    There are many tutorials on how to get started with Core Data, if you have an average experience with iOS, it will be a piece of cake for ya.

    Here's a nice tutorial that will help you setup core data in your project:

    https://www.raywenderlich.com/173972/getting-started-with-core-data-tutorial-2