ios - 在 iOS 上保存大型数组的最佳方法

标签 ios core-data save plist bluetooth-lowenergy

我编写了一个与 BLE 设备交互的 iOS 应用程序 - BLE 设备发送 iOS 设备数据,应用程序分析数据然后保存它。 iOS 应用程序每秒都会接收数据,因此我保存读数的数组(作为 NSString)很快就会变大。

该应用程序已启用在后台工作,到目前为止,我一直在使用 NSUserDefaults 来保存这个大数组。我对我的应用程序进行了跟踪,发现它在后台使用了 iPhone 6 CPU 的 3%,并发现 NSUserDefaults 导致了这种情况。我仔细阅读了它,发现 NSUserDefaults 为此目的效率有多低。

现在,我想放弃这种方法并使用不同的方法。我读过一些此类方法,例如将数据保存到 CoreData、Plist 或纯文本文件中。这些方法的效率和实现难度如何?我之前用文本文件做过一些事情,这非常简单,但很多时候我需要获取该文本文件的全部内容并将其加载到数组中进行解析,这似乎会给内存带来问题。因此,如果您有任何建议,我很乐意听到。

最佳答案

查看 Apple Performance Tips ,我发现了一些与您的问题有关的内容。

简而言之:在写入磁盘之前获取大量数据,以最大程度地减少使用 Core Data 或 SQLite 对闪存驱动器的访问。

您可以在this link中查看如何实现SQLite持久化


改进文件管理 - 性能提示

Minimize the amount of data you write to the disk. File operations are relatively slow and involve writing to the flash drive, which has a limited lifespan. Some specific tips to help you minimize file-related operations include:

  • If your data consists of structured content that is randomly accessed, store it in a Core Data persistent store or a SQLite database, especially if the amount of data you are manipulating could grow to more than a few megabytes.

关于ios - 在 iOS 上保存大型数组的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35368119/

相关文章:

iphone - touchesBegan - iPhone 应用程序 UIView

objective-c - NSURLRequest/NSURLConnection ios 5.0 v/s 早期版本

ios - 如何让 uitableViewCell 同时处理点击和长按?

ios - 在核心数据中使用日期属性在 TableView Controller 中创建节标题

ios - 从 layoutSubviews 访问上一个单元格

iphone - 核心数据,NSFetchRequest返回NSDictionaryResultType时如何获取NSManagedObject的ObjectId?

ios - 如何在核心数据中存储数组(Swift)

javascript - 保存可拖动div jQuery的位置

python - 如何在目录中的所有文件上运行 python 脚本?

c# - 使用锁定语句