存储iOS应用程序数据的最佳方法? [英] Best method to store data for an iOS app?

查看:71
本文介绍了存储iOS应用程序数据的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在学习快速的过程中开发一个库存/物品库存应用程序.基本上,它将是具有商品名称,数量和位置的东西.

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.

例如

25岁的灯泡,工作货车

6个仓库的开关

当用户输入此数据并按下按钮时,什么是存储此数据并在以后检索的最佳方法.我知道我可以将此附加到数组并显示该数组,但是如果应用程序关闭,该怎么办?

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?

推荐答案

如果要存储的数据很少且不敏感,则可以使用UserDefaults 例如,用户名,年龄等.

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.

对于大量数据,您应该使用Core Data,它是一种管理对象的好方法.例如,您有1000个项目,每个项目都有一个属性,基本上可以使用核心数据.这非常简单,例如如何创建托管对象,存储它们以及以后如何使用查询检索它们.

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.

基本上,当您使用核心数据配置项目时,项目会创建一个附加到项目的sqlite文件.

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

关于如何开始使用Core Data的教程很多,如果您对iOS有一般的经验,那对您来说简直是小菜一碟.

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

这篇关于存储iOS应用程序数据的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆