MigrationChain

public struct MigrationChain : ExpressibleByNilLiteral, ExpressibleByStringLiteral, ExpressibleByDictionaryLiteral, ExpressibleByArrayLiteral, Equatable
extension MigrationChain: CustomDebugStringConvertible, CoreStoreDebugStringConvertible

A MigrationChain indicates the sequence of model versions to be used as the order for progressive migrations. This is typically passed to the SchemaHistory or the DataStack initializer and will be applied to all stores added to the DataStack with addStorage(...) and its variants.

Initializing with empty values (either nil, [], or [:]) instructs the DataStack to use the .xcdatamodel’s current version as the final version, and to disable progressive migrations:

let dataStack = DataStack(migrationChain: nil)

This means that the mapping model will be computed from the store’s version straight to the DataStack‘s model version. To support progressive migrations, specify the linear order of versions:

let dataStack = DataStack(migrationChain:
   ["MyAppModel", "MyAppModelV2", "MyAppModelV3", "MyAppModelV4"])

or for more complex migration paths, a version tree that maps the key-values to the source-destination versions:

let dataStack = DataStack(migrationChain: [
    "MyAppModel": "MyAppModelV3",
    "MyAppModelV2": "MyAppModelV4",
    "MyAppModelV3": "MyAppModelV4"
])

This allows for different migration paths depending on the starting version. The example above resolves to the following paths:

  • MyAppModel-MyAppModelV3-MyAppModelV4
  • MyAppModelV2-MyAppModelV4
  • MyAppModelV3-MyAppModelV4

The MigrationChain is validated when passed to the DataStack and unless it is empty, will raise an assertion if any of the following conditions are met:

  • a version appears twice in an array
  • a version appears twice as a key in a dictionary literal
  • a loop is found in any of the paths
  • Initializes the MigrationChain with empty values, which instructs the DataStack to use the .xcdatamodel’s current version as the final version, and to disable progressive migrations.

    Declaration

    Swift

    public init()
  • Initializes the MigrationChain with a single model version, which instructs the DataStack to use the the specified version as the final version, and to disable progressive migrations.

    Declaration

    Swift

    public init(_ value: String)
  • Initializes the MigrationChain with a linear order of versions, which becomes the order of the DataStack‘s progressive migrations.

    Declaration

    Swift

    public init<T>(_ elements: T) where T : Collection, T.Element == String
  • Initializes the MigrationChain with a version tree, which becomes the order of the DataStack‘s progressive migrations.

    Declaration

    Swift

    public init(_ elements: [(String, String)])
  • Initializes the MigrationChain with a version tree, which becomes the order of the DataStack‘s progressive migrations.

    Declaration

    Swift

    public init(_ dictionary: [String : String])

ExpressibleByNilLiteral

ExpressibleByStringLiteral

ExtendedGraphemeClusterLiteralConvertible

UnicodeScalarLiteralConvertible

ExpressibleByDictionaryLiteral

ExpressibleByArrayLiteral

Equatable

  • Declaration

    Swift

    public static func == (lhs: MigrationChain, rhs: MigrationChain) -> Bool

CustomDebugStringConvertible

  • Declaration

    Swift

    public var debugDescription: String { get }