EasyRealm
EasyRealm是一个微框架(小于200行代码),帮助您使用Realm。
版本指南
Swift | Realm | EasyRealm |
---|---|---|
3.0 | >= 2.4 | 2.0.1 |
3.2 / 4.0 | >= 3.1.0 | >= 3.0.0 |
4.2 | >= 3.10 | >= 3.4.0 |
主要特性
EasyRealm将许多特性导入为:
- 深度级联删除
- 深度未管理对象
- 从未管理对象获取管理对象。
- 多线程操作(保存/编辑/删除/查询)
Promise
EasyRealm实现4个Promise:
- EasyRealm永远不会秘密地将一个未管理对象转换为一个管理对象,反之亦然。
- EasyRealm允许您以相同的方式使用管理对象和未管理对象。
- EasyRealm绝不会在你背后操作线程,你始终完全掌控流程。
- EasyRealm不会为你处理错误。
示例
使用
- 无继承。
- 无协议。
- 导入框架
- 享受
保存
保存对象
let pokemon = Pokemon()
try pokemon.er.save(update: true)
//OR
let managed = try pokemon.er.saved(update: true)
编辑
编辑对象
let pokemon = Pokemon()
try pokemon.er.edit {
$0.level = 42
}
删除
删除对象
let pokemon = Pokemon(name: "Pikachu")
try pokemon.er.delete()
//or
try pokemon.er.delete(with: .simple)
//or
try pokemon.er.delete(with: .cascade)
删除所有对象
try Pokemon.er.deleteAll()
查询
查询某一类型的所有对象
let pokemons = try Pokemon.er.all()
通过其主键查询一个对象
let pokemon = Pokemon.er.fromRealm(with: "Pikachu")
辅助变量
- isManaged
pokemon.er.isManaged // Return true if realm != nil and return false if realm == nil
- 管理
pokemon.er.managed // Return the managed version of the object if one exist in Realm Database
- 非管理
pokemon.er.unmanaged // Return an unmanaged version of the object
安装
EasyRealm 通过 CocoaPods 提供。要安装它,只需在 Podfile 中添加以下行
CocoaPods
use_frameworks!
pod "EasyRealm", '~> 3.2.0'
Carthage
github 'PoissonBallon/EasyRealm'
作者
- PoissonBallon @poissonballon
许可协议
EasyRealm 使用 MIT 许可协议。更多信息请参阅 LICENSE 文件。