[![CI Status](http://img.shields.io/travis/SAKAI, Atsushi/Migrator.svg?style=flat)](https://travis-ci.org/SAKAI, Atsushi/Migrator)
Migrator
is a library for performing the migration of the data when the iOS app has been upgraded.- This library has implemented by Swift Language and inspired by MFMigrationManager.
To run the example project, clone the repo, and run pod install
from the Example directory first.
And please read my test code, you can understand the more specific usage.
// 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()
You can implement delegate methods to get migration results.
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!!")
}
This library corresponds to Swift 2.0 Error Handling
The Swift Programming Language
// 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)!!")
}
Migrator is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "Migrator"
SAKAI, Atsushi, sakai.atsushi@gmail.com
Migrator is available under the MIT license. See the LICENSE file for more info.