mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-17 23:13:52 +01:00
minor changes before Swift 2.0
This commit is contained in:
@@ -48,7 +48,7 @@ public extension DataStack {
|
||||
isDirectory: false
|
||||
),
|
||||
configuration: configuration,
|
||||
sourceBundles: sourceBundles
|
||||
mappingModelBundles: mappingModelBundles
|
||||
)
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public extension DataStack {
|
||||
|
||||
:param: fileURL the local file URL for the SQLite persistent store.
|
||||
:param: configuration an optional configuration name from the model file. If not specified, defaults to `nil` which indicates the "Default" configuration.
|
||||
:param: sourceBundles an optional array of bundles to search mapping model files from. If not set, defaults to the `NSBundle.allBundles()`.
|
||||
:param: mappingModelBundles an optional array of bundles to search mapping model files from. If not set, defaults to the `NSBundle.allBundles()`.
|
||||
:return: a `MigrationType` indicating the type of migration required for the store; or `nil` if either inspection of the store failed, or no mapping model was found/inferred. `MigrationType` acts as a `Bool` and evaluates to `false` if no migration is required, and `true` if either a lightweight or custom migration is needed.
|
||||
*/
|
||||
public func needsMigrationForSQLiteStore(fileURL: NSURL = defaultSQLiteStoreURL, configuration: String? = nil, mappingModelBundles: [NSBundle] = NSBundle.allBundles() as! [NSBundle]) -> MigrationType? {
|
||||
|
||||
@@ -35,8 +35,14 @@ public struct MigrationChain: NilLiteralConvertible, StringLiteralConvertible, D
|
||||
|
||||
public func contains(version: String) -> Bool {
|
||||
|
||||
return self.latestVersion == version
|
||||
|| find(self.versionTree.keys, version) != nil
|
||||
return self.rootVersions.contains(version)
|
||||
|| self.leafVersions.contains(version)
|
||||
|| self.versionTree[version] != nil
|
||||
}
|
||||
|
||||
public func nextVersionFrom(version: String) -> String? {
|
||||
|
||||
return self.versionTree[version]
|
||||
}
|
||||
|
||||
|
||||
@@ -44,8 +50,9 @@ public struct MigrationChain: NilLiteralConvertible, StringLiteralConvertible, D
|
||||
|
||||
public init(nilLiteral: ()) {
|
||||
|
||||
self.latestVersion = nil
|
||||
self.versionTree = [:]
|
||||
self.rootVersions = []
|
||||
self.leafVersions = []
|
||||
}
|
||||
|
||||
|
||||
@@ -53,16 +60,18 @@ public struct MigrationChain: NilLiteralConvertible, StringLiteralConvertible, D
|
||||
|
||||
public init(stringLiteral value: String) {
|
||||
|
||||
self.latestVersion = value
|
||||
self.versionTree = [:]
|
||||
self.rootVersions = [value]
|
||||
self.leafVersions = [value]
|
||||
}
|
||||
|
||||
// MARK: ExtendedGraphemeClusterLiteralConvertible
|
||||
|
||||
public init(extendedGraphemeClusterLiteral value: String) {
|
||||
|
||||
self.latestVersion = value
|
||||
self.versionTree = [:]
|
||||
self.rootVersions = [value]
|
||||
self.leafVersions = [value]
|
||||
}
|
||||
|
||||
|
||||
@@ -70,8 +79,9 @@ public struct MigrationChain: NilLiteralConvertible, StringLiteralConvertible, D
|
||||
|
||||
public init(unicodeScalarLiteral value: String) {
|
||||
|
||||
self.latestVersion = value
|
||||
self.versionTree = [:]
|
||||
self.rootVersions = [value]
|
||||
self.leafVersions = [value]
|
||||
}
|
||||
|
||||
|
||||
@@ -84,15 +94,17 @@ public struct MigrationChain: NilLiteralConvertible, StringLiteralConvertible, D
|
||||
versionTree[tuple.0] = tuple.1
|
||||
return versionTree
|
||||
}
|
||||
let latestVersions = elements.filter { (tuple: (String, String)) -> Bool in
|
||||
|
||||
return versionTree[tuple.1] == nil
|
||||
}
|
||||
let leafVersions = Set(
|
||||
elements.filter { (tuple: (String, String)) -> Bool in
|
||||
|
||||
return versionTree[tuple.1] == nil
|
||||
|
||||
}.map { $1 }
|
||||
)
|
||||
|
||||
CoreStore.assert(latestVersions.count == 1, "\(typeName(MigrationChain))'s migration chain could not be resolved due to multiple leaf versions.")
|
||||
|
||||
self.latestVersion = latestVersions.first?.1
|
||||
self.versionTree = versionTree
|
||||
self.rootVersions = Set(versionTree.keys).subtract(versionTree.values)
|
||||
self.leafVersions = leafVersions
|
||||
}
|
||||
|
||||
|
||||
@@ -114,13 +126,15 @@ public struct MigrationChain: NilLiteralConvertible, StringLiteralConvertible, D
|
||||
}
|
||||
|
||||
self.versionTree = versionTree
|
||||
self.latestVersion = elements.last
|
||||
self.rootVersions = Set(flatMap([elements.first]) { $0 == nil ? [] : [$0!] })
|
||||
self.leafVersions = Set(flatMap([elements.last]) { $0 == nil ? [] : [$0!] })
|
||||
}
|
||||
|
||||
|
||||
// MARK: Internal
|
||||
|
||||
internal let latestVersion: String?
|
||||
internal let rootVersions: Set<String>
|
||||
internal let leafVersions: Set<String>
|
||||
|
||||
|
||||
// MARK: Private
|
||||
|
||||
@@ -57,7 +57,10 @@ public final class DataStack {
|
||||
modelName,
|
||||
ofType: "momd"
|
||||
)
|
||||
CoreStore.assert(modelFilePath != nil, "Could not find a \"momd\" resource from the main bundle.")
|
||||
CoreStore.assert(
|
||||
modelFilePath != nil,
|
||||
"Could not find a \"momd\" resource from the main bundle."
|
||||
)
|
||||
|
||||
let managedObjectModel: NSManagedObjectModel! = NSManagedObjectModel(contentsOfURL: NSURL(fileURLWithPath: modelFilePath)!)
|
||||
CoreStore.assert(
|
||||
|
||||
Reference in New Issue
Block a user