Files
POCloud-iOS/pocloud/Model/Migrations.swift
2018-06-06 18:39:18 -05:00

45 lines
1.4 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//
// Migrations.swift
// pocloud
//
// Created by Patrick McDonagh on 6/6/18.
// Copyright © 2018 patrickjmcd. All rights reserved.
//
import Foundation
import RealmSwift
class Migrations {
func checkSchema() {
let config = Realm.Configuration(
// Set the new schema version. This must be greater than the previously used
// version (if you've never set a schema version before, the version is 0).
schemaVersion: 1,
// Set the block which will be called automatically when opening a Realm with
// a schema version lower than the one set above
migrationBlock: { migration, oldSchemaVersion in
// We havent migrated anything yet, so oldSchemaVersion == 0
print(oldSchemaVersion)
switch oldSchemaVersion {
case 1:
break
default:
// Nothing to do!
self.zeroToOne(migration: migration)
}
})
Realm.Configuration.defaultConfiguration = config
print("Migration done")
}
func zeroToOne(migration : Migration) {
print("Performing migration from 0 to 1")
migration.enumerateObjects(ofType: Company.className(), { (oldObject, newObject) in
migration.delete(oldObject!)
})
}
}