当前位置:网站首页>iPhone开发 数据持久化总结(终结篇)—5种数据持久化方法对比
iPhone开发 数据持久化总结(终结篇)—5种数据持久化方法对比
2022-07-26 18:34:00 【51CTO】
本篇对IOS中常用的5种数据持久化方法进行简单对比总结
第1种:UserDefaults( iPhone开发【二十】数据持久化总结之第1篇—NSUserDefaults)
1)易用性很强
2)数据存储在.plist文件中
3)一般保存 配置信息,首选项信息、缓存数据等,适用存储较少量数据的情况
4)缺点:无法将自定义对象序列化到属性列表中
第2种:属性列表( iPhone开发【二十一】数据持久化总结之第2篇—属性文件(.plist))
1)易用性较强
2)数据存储在.plist文件中
3)一般用于存储少量数据,也不适合操作处理大量数据
4)缺点:无法将自定义对象序列化到属性列表中
这种方法与第1种非常相像,首选项信息、缓存数据等一般用第1种,其它情况一般用第二种方法。
第3种:归档( iPhone开发【二十二】数据持久化总结之第3篇—归档(NSKeyedArchiver、NSKeyedUnarchiver))
1)易用性较强
2)数据存储archive文件中
3)一般用于存储少量数据
4)最大的优点是:可以将复杂的对象写入文件 可以归档集合类,所以无论添加多少对象,将对象写入磁盘的方式都是一样的,不会增加工作量;
而如果用第2种方法的属性列表一则无法保存复杂对象,二则工作量会随着对象的增加而加大
第4种:sqlite3( iPhone开发【二十四】数据持久化总结之第4篇—sqlite3数据库)
1)IOS 相关api都是C语言接口,且设计的易用性不强
2)数据存储在.db3(或sqlite3)数据库中,
3)可以存储大量数据,存储、检索大量数据非常高效;
开源的嵌入式数据库,ACID事务,
能对数据进行复杂的聚合,比使用对象执行这些操作要高效得多。
轻量级,跨平台,占用资源非常低,无网络服务器,只提供数据库级别的锁定,无用户账户概念。
SQLite的API不区分当前操作的数据库是在内存还是在文件。
缺点:
1. 并发访问的锁机制
SQLite在并发(包括多进程和多线程)读写方面的性能不太理想。数据库可能会被写操作独占,从而导致其它读写操作阻塞或出错;
2. SQL标准支持不全
如不支持外键约束;
PS:封装sqlite3操作的两个常用框架 BNRPersistence
fmdb(更面向对象,省去麻烦冗余的C代码,比coredata更轻量级,提供多线程安全的数据库操作,有效防止数据库混乱)
三个核心类:FMDatabase :一个对象代表一个单独的数据库
FMResultSet :查询后的结果集
FMDatebaseQueue:线程安全的执行多个查询或更新
缺点:不支持多线程同时使用同一个数据库连接操作。
第5种:CoreData( iPhone开发【二十六】数据持久化总结之第5篇—CoreData技术)
类似java中的Hibernate
1)个人感觉易用性不强
2)数据存储可以选择sqlite,xml,plist或是其他方式作为持久化方案,一般使用sqlite
3)优点:实现的功能包括redo,undo,数据验证等
边栏推荐
- jar文件 反编译(IDEA环境)
- A case study of building an efficient management system for a thousand person food manufacturing enterprise with low code
- Adjust the array order so that odd numbers precede even numbers and their relative positions remain the same
- Selenium+Web自动化框架的Case
- The inventory of chips in the United States is high, and the shipment of chips in China has increased rapidly and the import of 28.3 billion chips has been greatly reduced. TSMC has a showdown
- 指标和标签是做什么的
- 密码一致,总显示如下图
- Conda+pytorch environment tutorial
- Difficult performance problems solved in those years -- ext4 defragmentation
- Using MySQL master-slave replication delay to save erroneously deleted data
猜你喜欢

B站SRE负责人亲述 713事故后的多活容灾建设|TakinTalks大咖分享

关于接口测试你想知道的都在这儿了

C # get local time / system time

DDL,DQL,DML语句

cuda11.2对应pytorch安装

YOLO V2详解

AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘

还在用Xshell?你out了,推荐一个更现代的终端连接工具

Redis introduction
![Design of intelligent weighing system based on Huawei cloud IOT (STM32) [II] there is information at the end](/img/55/ca86fd1a53eb61efc70fead08ff0ad.png)
Design of intelligent weighing system based on Huawei cloud IOT (STM32) [II] there is information at the end
随机推荐
conda转移项目虚拟环境必备技能+pip速度下载太慢解决办法
AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘
Several ways to view containers
Leetcode-138-copy linked list with random pointer
Network protocol: tcp/ip protocol
查看容器的几种方式
J3: redis master-slave replication
The inventory of chips in the United States is high, and the shipment of chips in China has increased rapidly and the import of 28.3 billion chips has been greatly reduced. TSMC has a showdown
彻底关闭win10自动更新
After working for 13 years, I have a little software testing experience and feelings
2022/07/26 学习笔记 (day16) 链表和栈
Spatiotemporal prediction 5-gat
Chapter 9 practical modeling technology
UIAutomator2常用类之UiObject2
DDL,DQL,DML语句
Conda+pytorch environment tutorial
Vs2019 export import configuration
2022 build enterprise level data governance system
Selenium + case of Web Automation Framework
File depth monitoring strategy