DKDBManager 1.1.0

DKDBManager 1.1.0

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布上次发布2017年6月

DKDBManager.podspec 维护。



  • 作者
  • kevindelord

概念

DKDBManager 是围绕 Magical Record 的简单但非常有用的 CRUD 管理器。

它实现了数据库逻辑,帮助开发者管理实体,并让他专注于不仅仅是数据管理的事物。

主要概念是将表示实体的 JSON 字典导入到数据库中。

在一些模型类配置之后,只需要一个函数来 创建读取更新删除 实体!

文档

完整文档可在 CocoaDocs 提供。

此外,Wiki 包含有关库不同逻辑的所有信息和细节。

快速概述

使用 DKDBManagerMagicalRecord,您可以轻松创建、更新或删除实体。

要这样做您需要位于一个 savingContext 并使用适当的 DKDBManager 函数。

DKDBManager.saveWithBlock { (savingContext: NSManagedObjectContext) in

    // Perform saving code here, against the `savingContext` instance.
    // Everything done in this block will occur on a background thread.

	let plane = Plane.crudEntityInContext(savingContext)
	plane?.origin = "London"
    plane?.destination = "Paris"
}

在此执行块结束时,所有更改都将保存(或 合并 )到默认上下文。

此后,新的 Plane 实体将在主线程的默认上下文中可用。

或者您可以使用 JSON 结构 CRUD 一个实体

let planeJSON = ["origin":"Paris", "destination":"London"]
Plane.crudEntityWithDictionary(planeJSON, inContext: savingContext, completion: { (entity: AnyObject?, state: DKDBManagedObjectState) in

	// The CRUDed plane is referenced in the `entity`.
	// Its actual state is described as follow:
	switch state {
	case .Create:	// The entity has been created, it's all fresh new.
	case .Update:	// The entity has been updated, its attributes changed.
	case .Save:		// The entity has been saved, nothing happened.
	case .Delete:	// The entity has been removed.
	}
})

state 变量描述了实体发生了什么。

建议实现其他功能,比如用一个给定的字典更新当前实体的功能。

没有这个函数,实体的属性将永远不会设置或更新。

给定的 dictionary 对象是用于启动 CRUD 过程 的同一个对象。

override func updateWithDictionary(dictionary: [NSObject : AnyObject]?, inContext savingContext: NSManagedObjectContext) {
	super.updateWithDictionary(dictionary, inContext: savingContext)
	// Update attributes
	self.origin 		= GET_STRING(dictionary, "origin")
	self.destination 	= GET_STRING(dictionary, "destination")
}

更多内容请参阅 Wiki:bowtie:

试试看!

查看示例项目

$> pod try DKDBManager

作者

kevindelord, [email protected]