将数据本地存储在iphone上 [英] storing data locally on the iphone

查看:159
本文介绍了将数据本地存储在iphone上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个应用程序,我想在设备上本地存储用户信息,而不使用任何服务器数据库 - 但一切在设备端。我想存储特定的用户位置并在表视图中显示它,所以即使用户以后启动应用程序 - 我可以拉历史记录和进给历史表与过去的位置。基本上来自本地数据库的读/写能力。

I am building an app where I'd like to store user information locally on the device, without using any server database - but everything on the device side. I am looking to store specific user locations and show it in a table view, and so even when the user launches the app later - I can pull the history and feed the history table with the past locations. Basically a read/write capability from a local database.

现在,我知道以前有很多问题,但是我找不到一个在没有外部数据库的情况下本地保存数据的问题。我不知道,例如,使用Core Data是在这里做正确和最简单的事情。

Now, I know that there were many questions like that before but I could not find one that addresses saving data locally without an external data base. I am not sure, for example, that using Core Data is the correct and simplest thing to do here.

不喜欢任何建议。

推荐答案

对于简单数据,您应该使用NSUserDefaults。 CoreData非常酷,但主要是存储DB结构,并引入复杂性(但我喜欢它:))。如果你只需要存储String,Array等(基本上是prefs),你可以使用NSUserDefaults:

For simple data you should use NSUserDefaults. CoreData is very cool but mainly to store DB structures, and introduces complexity (but i love it:)). If you just need to store String, Array and so on (basically prefs), you can go with NSUserDefaults:

例如:

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];  //load NSUserDefaults
NSArray *fakeFavs = [[ NSArray alloc] initWithObjects:@"2",@"4", @"100", nil];  //declare array to be stored in NSUserDefaults
[prefs setObject:fakeFavs forKey:@"favourites"];  //set the prev Array for key value "favourites"

这篇关于将数据本地存储在iphone上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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