mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-16 14:06:53 +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(
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<key>IDESourceControlProjectIdentifier</key>
|
||||
<string>B6855E48-4B19-4321-B1C7-CB2706E12777</string>
|
||||
<key>IDESourceControlProjectName</key>
|
||||
<string>project</string>
|
||||
<string>CoreStoreDemo</string>
|
||||
<key>IDESourceControlProjectOriginsDictionary</key>
|
||||
<dict>
|
||||
<key>4B60F1BCB491FF717C56441AE7783C74F417BE48</key>
|
||||
@@ -16,7 +16,7 @@
|
||||
<string>github.com:JohnEstropia/GCDKit.git</string>
|
||||
</dict>
|
||||
<key>IDESourceControlProjectPath</key>
|
||||
<string>CoreStoreDemo/CoreStoreDemo.xcodeproj/project.xcworkspace</string>
|
||||
<string>CoreStoreDemo/CoreStoreDemo.xcodeproj</string>
|
||||
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
|
||||
<dict>
|
||||
<key>4B60F1BCB491FF717C56441AE7783C74F417BE48</key>
|
||||
|
||||
@@ -406,7 +406,7 @@ There are currently 5 fetch methods you can call from `CoreStore`, from a `DataS
|
||||
- `fetchAll(...)` - returns an array of all objects that match the criteria.
|
||||
- `fetchOne(...)` - returns the first object that match the criteria.
|
||||
- `fetchCount(...)` - returns the number of objects that match the criteria.
|
||||
- `fetchObjectIDs(...)`` - returns an array of `NSManagedObjectID`s for all objects that match the criteria.
|
||||
- `fetchObjectIDs(...)` - returns an array of `NSManagedObjectID`s for all objects that match the criteria.
|
||||
- `fetchObjectID(...)` - returns the `NSManagedObjectID`s for the first objects that match the criteria.
|
||||
|
||||
Each method's purpose is straightforward, but we need to understand how to set the clauses for the fetch.
|
||||
@@ -450,7 +450,7 @@ var mostValuablePeople = CoreStore.fetchAll(
|
||||
OrderBy(.Descending("rating"), .Ascending("surname"))
|
||||
)
|
||||
```
|
||||
As seen above, `OrderBy` accepts a list of `SortKey` enumeration values, which can be either `.Ascending` or `.Descending`. The associated value for the `SortKey` enumeration is the attribute key string.
|
||||
As seen above, `OrderBy` accepts a list of `SortKey` enumeration values, which can be either `.Ascending` or `.Descending`.
|
||||
|
||||
You can use the `+` and `+=` operator to append `OrderBy`s together. This is useful when sorting conditionally:
|
||||
```swift
|
||||
|
||||
Reference in New Issue
Block a user