NSUserDefaults的局限性是什么? [英] What are the limitations of NSUserDefaults?

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

问题描述

在iPhone中永久存储数据通常使用Core Data或sqlite3来完成。大多数人喜欢使用NSUserDefaults作为应用程序首选项的存储,而不是将其用作普通数据库(如sqlite)。

Storing data permanently in an iPhone is usually done using Core Data or sqlite3. Most people prefer to user NSUserDefaults as a storage for application preferences, rather than using it as a normal database (such as sqlite).

我发现大量数据可以存储在NSUserDefaults,它是非常容易使用,它是快速。那么为什么不使用这个永久存储?
NSUserDefaults作为数据库的限制是什么?

I have found that large amount of data can be stored in NSUserDefaults, it is extremely easy to use and it is fast. So why not use this as a permanent storage? What are the limitations of NSUserDefaults as a database?

更新:

我经常使用三种不同的

Update:
I frequently use three different ways of saving my data to disk.


  • 核心数据

  • 将对象序列化到plists

  • NSUserDefaults

我不再使用FMDB
每种方法的主要优点和缺点是什么?

I do not use FMDB (or sqlite directly) anymore. What are the main advantages and disadvantages of each approach?

我遇到的NSUserDefaults的一些优点:

Some advantages of NSUserDefaults that I've come across:


  • 分组等可以很容易地使用NSPredicate来完成。

  • NSUserDefaults是线程安全的。

  • 它需要一行来获取和保存数据到NSUserDefaults。

推荐答案

NSUserDefaults提供了一个简单的学习曲线和线程安全的实现。

NSUserDefaults offers a trivial learning curve and thread safe implementation.

否则我发现Core Data在各方面都有优势。特别是关于配置默认值和迁移例程。

Otherwise I've found Core Data superior in every way. Especially with regards to configuring default values and migration routines.

编辑:事实证明,NSUserDefaults线程安全性似乎来自主线程上的运行操作。这在我的一个应用程序中造成严重的跳帧;我结束了剥离NSUserDefaults,并将其替换为一个线程安全的NSMutableDictionary,它被序列化到一个文件。

As it turns out, NSUserDefaults "thread-safeness" seems to come from running operations on the main-thread. This caused severe frame-skipping in one of my applications; I ended up ripping out NSUserDefaults and replacing it with a thread-safe NSMutableDictionary which gets serialized to a file.

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

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