迁移工具
是一个库,用于在 iOS 应用程序升级时进行数据迁移。要运行示例项目,请克隆仓库,然后首先从 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 文件。