在iOS应用上保存数据的最有效的方法 [英] Most efficient way to save data on iOS Apps
问题描述
我正在创建一个包含多个UITableViewControllers的应用程序。到目前为止,我已经使所有的连接到我的不同的JSONGetStuff.php文件,然后从我的数据库获取数据与JSON编码。这工作伟大。大多数表格都有包含文本和图像的单元格。现在我有四个tableViews包含不同的数据,我觉得保存数据,而不是每次加载。现在我让应用程序访问ViewDidLoad上的JSON.php文件,并将数据存储在NSArray中,然后通过NSDictionary解析它们以获取ObjectForKey:@;此数据是来自SQL服务器的正常表,例如NameAdressImageName等。
I am creating an App containing multiple UITableViewControllers. So far I have made all of them connect to my different JSONGetStuff.php files, then getting the data from my database with a JSON encode. This works great. Most tables have cells containing both text and image. Now that I have four tableViews containing different data, I feel like saving the data rather than loading it each time. Now I make the app access the JSON.php files on ViewDidLoad, and store the data in an NSArray, and then parse them through NSDictionary to get ObjectForKey:@""; This data is a normal table from a SQL server, like "Name" "Adress" "ImageName" etc.
我意识到我不会更新数据库太频繁,很可能每月一次或两次,甚至更少。所以我决定我想把信息存储在应用程序。
I have realized that I'm not going to update the database too often, most likely once or twice a month, maybe even less. So I decided I want to store the information in the app insted. Not in the way that I have to release an update everytime I change the database, but like saving until updated.
我想我应该有一个名为版本的整数,而不是每次我更改数据库时发布更新我的应用程序,= 1;发布。然后,当应用程序启动时,我想让应用程序去www.mywebsite.com/version.php,并检查变量回声是否与版本相同。每当我改变我的数据库,我可以改变这个整数++。当应用程序启动并检查版本,并且在本地是错误的,那么我想要它下载整个负载,并覆盖存储在iPhone上的当前数据。
I figured I should have an integer named "Version" in my app, being = 1; on release. Then, when the app is launched, I want to make the app go to www.mywebsite.com/version.php, and check if the variable echoed out is the same as "Version". Whenever I change my database, I can change this integer ++. When the app launches, and checks the version, and it is wrong locally, then I want it to download the whole load, and overwrite the current data stored on the iPhone.
我没有线索从哪里开始。我使用JSON,因为它不好直接连接到数据库,但由于我的数据是数据库数据,我可以创建一个本地数据库,并使用该信息,而不是一个数组?我读某处,也许.plist更好的字符串,我的整个数据库只是字符串(varchar x)。
I have no clue where to begin. I use JSON because it's bad to connect directly to a database, but since the my data is database-data, could I create a local database and use that information instead of an Array? I read somewhere that maybe .plist was better for strings, and my whole database is just strings (varchar x).
我在哪里保存初始数据?如何解析我的数据库数据在那里使用即JSON?当时间到来时,如何覆盖该数据?我从哪里开始?我应该阅读.plist,NSData,NSCoding或NSFileManager?
Where do I save the initial data? How do I parse my database-data over there using i.e JSON? How do I overwrite that data when the time has come? And where do I begin? Should I read up on .plist, NSData, NSCoding or NSFileManager?
推荐答案
尝试考虑让数据持久存储在核心数据数据库。核心数据是一个处理数据库的持久性框架。核心数据为你处理了很多东西(关系,内存等),并且与表格(使用NSFetchedResultsController)非常相似。
Try to consider having the data persistent in a core data database. Core data is a persistent framework to handle databases. Core data handles a lot of stuff for you (relationships, memory, etc), and plays very well with tables (using NSFetchedResultsController).
这当然取决于数据量,但你可以开始看看链接的文档。
It will all depend on the amount of data, of course, but you can start taking a look at the linked document.
这篇关于在iOS应用上保存数据的最有效的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!