Swift 编写的轻量级 CoreData 管理器
Breeze 从 MagicalRecord 和 Nimble 中汲取了许多灵感和启发
然后,将 “Breeze.h” 导入您的 .pch 文件
首先,设置本地或 iCloud 存储
if BreezeStore.iCloudAvailable() {
BreezeStore.setupiCloudStoreWithContentNameKey("iCloudTestContentName", localStoreName: "iCloudTest", transactionLogs: "iCloud_transactions_logs")
} else {
BreezeStore.setupStoreWithName("Test", type: NSSQLiteStoreType, options: [NSMigratePersistentStoresAutomaticallyOption: true, NSInferMappingModelAutomaticallyOption: true])
}
BreezeStore.saveInBackground { contextType -> Void in
let car = Car.createInContextOfType(contextType)
car.color = UIColor.blueColor()
}
通过属性查找单个对象
let car = Car.findFirst(attribute: "myAttribute", value: 1, contextType: BreezeContextType.Main)
或通过谓词查找
let car = Car.findFirst(predicate: myPredicate, sortedBy: "anotherAttribute", ascending: false, contextType: BreezeContextType.Main)
同样地,通过属性查找所有对象
let cars = Car.findAll(attribute: "myAttribute", value: 1, contextType: BreezeContextType.Main)
或通过谓词查找
let cars = Car.findAll(predicate: myPredicate, sortedBy: "anotherAttribute", ascending: false, contextType: BreezeContextType.Main)
如果您只需要计数查询的对象,请使用 countAll 函数
let carCount = Car.countAll(predicate: myPredicate, sortedBy: "anotherAttribute", ascending: false, contextType: BreezeContextType.Main)
Breeze 在 MIT 许可证下可用。请参阅文件 LICENSE。