NSUserDefaults与sqlite3 [英] NSUserDefaults vs sqlite3

查看:81
本文介绍了NSUserDefaults与sqlite3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小的iPhone应用程序,用于存储对象列表.用户可以添加和删除对象,但是此列表将保持很小(大多数用户将具有10-30个对象). NSUserDefaults似乎更容易使用,但是sqlite3会更快吗?只有30条记录"会有明显区别吗?

I have a small iPhone app that stores a list of objects. The user can add and remove objects, but this list will remain fairly small (most users would have 10-30 objects). NSUserDefaults seems much easier to work with, but will sqlite3 be faster? With only 30 "records" will there be any noticeable difference?

推荐答案

NSUserDefaults用于用户首选项,通常是诸如NSString或NSNumber之类的基本对象. Sqlite(序列化属性列表中的对象集合)或Core Data是用于存储用户数据(例如您创建的模型对象)的所有有效选项.

NSUserDefaults is for user preferences, usually basic objects like NSString or NSNumber. Sqlite, serializing a collection of objects in a property list, or Core Data are all valid options for storing user data such as model objects you created.

您不会看到速度差异,但是仍然最好为正在执行的操作选择正确的机制.如果仅是首选项,则使用NSUserDefaults,否则我会将您的对象序列化为plist.如果您不熟悉Cocoa,那么我一开始会避免使用Core Data,甚至不要使用sqlite,以便有机会先学习基础知识.

You're not going to see a speed difference, but it's still best to pick the correct mechanism for what you're doing. If it's just preferences then use NSUserDefaults, otherwise I would serialize your objects to a plist. If you're new to Cocoa I would avoid Core Data and even sqlite at first, to give yourself a chance to learn the basics first.

这篇关于NSUserDefaults与sqlite3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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