GithubHelp home page GithubHelp logo

isabella232 / mtmigration Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ifttt/mtmigration

0.0 0.0 0.0 28 KB

Manages blocks of code that only need to run once on version updates in iOS apps.

License: BSD 2-Clause "Simplified" License

Ruby 8.20% Objective-C 91.80%

mtmigration's Introduction

MTMigration

Manages blocks of code that only need to run once on version updates in iOS apps. This could be anything from data normalization routines, "What's New In This Version" screens, or bug fixes.

Installation

MTMigration can be installed one of two ways:

  • Add pod "MTMigration" to your Podfile, import as necessary with: #import <MTMigration/MTMigration.h>.
  • Add MTMigration.{h,m} to your project, import as necessary with: #import "MTMigration.h".

Usage

By giving a version number and block of code to migrateToVersion:block:, MTMigration will ensure that the block of code is only ever run once.

[MTMigration migrateToVersion:@"1.1" block:^{
    [obj doSomeDataStuff];
}];

You would want to run this code in your app delegate or similar.

Because MTMigration inspects your *-info.plist file for your actual version number and keeps track of the last migration, it will migrate all un-migrated blocks inbetween. For example, let's say you had the following migrations:

[MTMigration migrateToVersion:@"0.9" block:^{
    // Some 0.9 stuff
}];

[MTMigration migrateToVersion:@"1.0" block:^{
    // Some 1.0 stuff
}];

If a user was at version 0.8, skipped 0.9, and upgraded to 1.0, then both the 0.9 and 1.0 blocks would run.

For debugging/testing purposes, you can call reset to clear out the last migration MTMigration remembered, causing all migrations to run from the beginning:

[MTMigration reset];

Notes

MTMigration assumes version numbers are incremented in a logical way, i.e. 1.0.1 -> 1.0.2, 1.1 -> 1.2, etc. MTMigration uses NSString#compare:options: to do the comparison, passing NSNumericSearch to options: so that 1.10 comes after 1.9.

Version numbers that are past the version specified in your app will not be run. For example, if your *-info.plist file specifies 1.2 as the app's version number, and you attempt to migrate to 1.3, the migration will not run.

Blocks are executed on the thread the migration is run on. Background/foreground situations should be considered accordingly.

Contributing

This library does not handle some more intricate migration situations, if you come across intricate use cases from your own app, please add it and submit a pull request. Be sure to add test cases.

Contributors

Parker Wightman (@parkerwightman)
Good Samaritans

mtmigration's People

Contributors

clafou avatar kylefleming avatar pwightman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.