迁移工具 0.2.0

迁移工具 0.2.0

测试已测试
语言语言 SwiftSwift
许可协议 MIT
发布时间最后发布2015年9月
SPM支持 SPM

radioboo 维护。



  • 作者
  • radioboo

迁移工具

  • 迁移工具 是一个库,用于在 iOS 应用程序升级时进行数据迁移。
  • 该库使用 Swift 语言实现,并受 MFMigrationManager 的启发。

使用方法

要运行示例项目,请克隆仓库,然后首先从 Example 目录运行 pod install。请阅读我的测试代码,您可以了解更具体的使用方法。

基本

// Migrator Snippets
let migrator: Migrator = Migrator()
migrator.setInitialVersion("1.0.0") // Starting point you want to save the migration history
migrator.registerHandler("1.0.1") { () -> Void in
    print("[Migrator] Migration to v1.0.0....")
}
migrator.migrate()

可选

代理方法

您可以实现代理方法以获取迁移结果。

let migrator: Migrator = Migrator()
migrator.delegate = self

func didSucceededMigration(migratedVersion: String) {
    print("[Migrator] Did Succeeded Migration to version \(migratedVersion)!!")
}

func didFailedMigration(migratedVersion: String) {
    print("[Migrator] Did Failed Migration to version \(migratedVersion)!!")
}

func didCompletedAllMigration() {
    print("[Migrator] Completed Migrations!!")
}

错误处理

这个库对应于 Swift 2.0 错误处理 Swift 编程语言

// Define your custom ErrorType
enum MigrationError: ErrorType {
  case UnexpectedError
}

let migrator: Migrator = Migrator()
migrator.delegate = self // you can recognize to throw error from handler with delegate.
migrator.registerHandler("1.0.1") { () throws -> Void in
    print("[Migrator] Migration to v1.0.0....")
    throw MigrationError.UnexpectedError // Migration Closure will throw Error
}
migrator.migrate()

// will call below delegate method
func didFailedMigration(migratedVersion: String) {
    print("[Migrator] Did Failed Migration to version \(migratedVersion)!!")
}

安装

迁移工具可以通过 CocoaPods 获取。要安装它,只需在 Podfile 中添加以下行:

pod "Migrator"

作者

SAKAI, Atsushi, [email protected]

许可协议

迁移工具在 MIT 许可协议下提供。有关更多信息,请参阅 LICENSE 文件。