GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - mallexxx/MigrateDecoder: Swift Codable schema migration implementation

BranchesTags
Open more actions menu

Latest commit

 

History

3 Commits
3 Commits

Folders and files

NameName
Last commit message
Last commit date
ModelMigrate.xcodeproj
ModelMigrate.xcodeproj
 
 
ModelMigrate
ModelMigrate
 
 
ModelMigrateTests
ModelMigrateTests
 
 
.gitignore
.gitignore
 
 
Readme.md
Readme.md
 
 

Repository files navigation

MigrateDecoder

MigrateDecoder is an implementation of the Schema Migration for Swift 4 Codable protocol.

Background

Suppose you've had a JSON data model in your app. You store the model in a JSON file, you use the new gorgeous Swift Codable protocol for serialization/deserialization and everything is beautiful. But one day you want to modify your model structure, here comes a tough choice:

  • To throw away all the user's data and begin from scratch
  • To introduce some Optional values in your new model and live with that
  • To use Schema Migration

If you go with the third option, it also introduces several ways to go:

  • To parse your old JSON into a dictionary and update the structure manually, then save it back and read into the new structure
  • To implement some kind of Schema Migration Tool
  • To use the MigrateDecoder framework 😀

Usage

  1. Add MigrateDecoder framework to your project

  2. When you make changes to your Model, save the old one with some modified name e.g. MyOldModel

  3. Add migration extension to your Old Model and the New Model:

import ModelMigrate

extension MyOldModel: NotMigratable {}

extension NewModel: Migratable {
    typealias MigratableFrom = MyOldModel

    init(migrating old: MyOldModel) throws {
        // Do the migration here
    }
}
  1. That's it!

See the tests included for a Demo!

About

Swift Codable schema migration implementation

Resources

Readme
Activity

Stars

1 star

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.