Skip to content

atsushisakai-gh/Migrator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Migrator

[![CI Status](http://img.shields.io/travis/SAKAI, Atsushi/Migrator.svg?style=flat)](https://travis-ci.org/SAKAI, Atsushi/Migrator) Version License Platform

  • 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.

Usage

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.

Basic

// 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()

Optional

Delegate Methods

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!!")
}

Error Handling

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)!!")
}

Installation

Migrator is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "Migrator"

Author

SAKAI, Atsushi, sakai.atsushi@gmail.com

License

Migrator is available under the MIT license. See the LICENSE file for more info.