在到处搜索之后,我发现SQLite,Realm,CoreData,UserDefaults和JSON文件之间没有适当的比较。
您可以轻松找到优点和缺点,但是很难知道该使用什么。
我知道决定完全取决于要求。但是仍然必须有一种决策的方法。
假设以下情况,哪种选择最适合个人,为什么?
保存用户观看的历史记录[大量数据,仅插入和删除操作]
保存联系电话[最多1000个电话号码,需要快速提取并连续运行]
保存简单的GET API请求[用于缓存]
注意:我不是在这里存储敏感信息。
随时添加/更新更多相关案例。
Available Options to save data in iOS.
User Default: Quicky persists a small amount of data.
Codable (NSCoder): for saving the custom object.
Keychain: Small bit of data securely.
SQLite: Persist large data but require query operation.
Core Data: Object-Oriented Database.
Realm: Faster and easier database solution.
CoreData, Sqlite & Realm store plain text in-store if you don't tell it to encrypt, you can use encryption in all to make it secure.
Saving user-watched history [Huge amount of data, Only insert, and delete operation] Coredata & Realm should be used.
Saving contact numbers [Max 1000 numbers, Need fast fetch, and continuous operation] Coredata & Realm should be used.
保存简单的GET API请求[用于缓存]应该使用Codable,Coredata和Realm。该响应可用于脱机存储。