Swift 编写的 CoreData 管理库:SugarRecord
jopen
10年前
使用Swift编写的CoreData管理库,开发者可通过它更简单地使用CoreData和REALM。
适合初级和高级开发者,完全自定义,语法友好,兼容OS X和iOS,文档支持完善,测试完善(所有组件均使用XCTest测试)。
可在不同的堆栈间进行更改,而不会影响到app的其余部分。
百分百Swift编写,对于Objective-C,需要封装。
如果需要在CoreData和Realm之间进行迁移,仅需确保项目的属性名称一致。
SugarRecord自动管理后台操作。
The scheme above shows the structure of SugarRecord. It's formed by:
- Database Models Extensions: To add the sugar syntax that links these models with SugarRecord and the database.
- Finder: SugarRecord custom element to abstract the querying components from the type of storage (Realm or CoreData)
- Core: Main component of the library that translates Save/Delete/Find calls into internal operations using the stacks set.
- SugarRecord contexts: Altough Realm doesn't have contexts as we have in CoreData, we have created abstracted contexts that surround the user operations with models independently if you are using CoreData or Realm. Yeah!
- Stack: The storage stack is another key piece in SugarRecord because it knows how and when persist/fetch/delete your objects into the database. You can tell SugarRecord which stack it should use.