WIP: Objective-C bridge (90% done!)

This commit is contained in:
John Estropia
2016-03-30 11:12:17 +09:00
parent 09d844f5df
commit 8b7af86526
17 changed files with 901 additions and 396 deletions

View File

@@ -69,7 +69,7 @@ public extension CoreStore {
}
)
```
- parameter storage: the local storage
- parameter storage: the storage
- parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. This closure is NOT executed if an error is thrown, but will be executed with a `.Failure` result if an error occurs asynchronously.
- returns: an `NSProgress` instance if a migration has started, or `nil` is no migrations are required
*/
@@ -104,7 +104,7 @@ public extension CoreStore {
Asynchronously adds a `LocalStorage` to the `defaultStack`. Migrations are also initiated by default.
```
try CoreStore.addStorage(
SQLiteStore(configuration: "Config1"),
SQLiteStore(fileName: "core_data.sqlite", configuration: "Config1"),
completion: { result in
switch result {
case .Success(let storage): // ...

View File

@@ -69,7 +69,7 @@ public extension DataStack {
}
)
```
- parameter storage: the local storage
- parameter storage: the storage
- parameter completion: the closure to be executed on the main queue when the process completes, either due to success or failure. The closure's `SetupResult` argument indicates the result. This closure is NOT executed if an error is thrown, but will be executed with a `.Failure` result if an error occurs asynchronously.
- returns: an `NSProgress` instance if a migration has started, or `nil` is no migrations are required
*/
@@ -143,7 +143,7 @@ public extension DataStack {
Asynchronously adds a `LocalStorage` to the stack. Migrations are also initiated by default.
```
try dataStack.addStorage(
SQLiteStore(configuration: "Config1"),
SQLiteStore(fileName: "core_data.sqlite", configuration: "Config1"),
completion: { result in
switch result {
case .Success(let storage): // ...

View File

@@ -57,7 +57,7 @@ import Foundation
}
```
*/
public enum MigrationResult {
public enum MigrationResult: BooleanType, Hashable {
/**
`MigrationResult.Success` indicates either the migration succeeded, or there were no migrations needed. The associated value is an array of `MigrationType`s reflecting the migration steps completed.
@@ -70,6 +70,34 @@ public enum MigrationResult {
case Failure(CoreStoreError)
// MARK: BooleanType
public var boolValue: Bool {
switch self {
case .Success: return true
case .Failure: return false
}
}
// MARK: Hashable
public var hashValue: Int {
switch self {
case .Success(let migrationTypes):
return self.boolValue.hashValue
^ migrationTypes.map { $0.hashValue }.reduce(0, combine: ^).hashValue
case .Failure(let error):
return self.boolValue.hashValue ^ error.hashValue
}
}
// MARK: Internal
internal init(_ migrationTypes: [MigrationType]) {
@@ -89,16 +117,20 @@ public enum MigrationResult {
}
// MARK: - MigrationResult: BooleanType
// MARK: - SetupResult: Equatable
extension MigrationResult: BooleanType {
@warn_unused_result
public func == (lhs: MigrationResult, rhs: MigrationResult) -> Bool {
public var boolValue: Bool {
switch (lhs, rhs) {
switch self {
case .Success: return true
case .Failure: return false
}
case (.Success(let migrationTypes1), .Success(let migrationTypes2)):
return migrationTypes1 == migrationTypes2
case (.Failure(let error1), .Failure(let error2)):
return error1 == error2
default:
return false
}
}

View File

@@ -31,7 +31,7 @@ import Foundation
/**
The `MigrationType` specifies the type of migration required for a store.
*/
public enum MigrationType: BooleanType {
public enum MigrationType: BooleanType, Hashable {
/**
Indicates that the persistent store matches the latest model version and no migration is needed
@@ -120,4 +120,45 @@ public enum MigrationType: BooleanType {
case .Heavyweight: return true
}
}
// MARK: Hashable
public var hashValue: Int {
let preHash = self.boolValue.hashValue ^ self.isHeavyweightMigration.hashValue
switch self {
case .None(let version):
return preHash ^ version.hashValue
case .Lightweight(let sourceVersion, let destinationVersion):
return preHash ^ sourceVersion.hashValue ^ destinationVersion.hashValue
case .Heavyweight(let sourceVersion, let destinationVersion):
return preHash ^ sourceVersion.hashValue ^ destinationVersion.hashValue
}
}
}
// MARK: - MigrationType: Equatable
@warn_unused_result
public func == (lhs: MigrationType, rhs: MigrationType) -> Bool {
switch (lhs, rhs) {
case (.None(let version1), .None(let version2)):
return version1 == version2
case (.Lightweight(let source1, let destination1), .Lightweight(let source2, let destination2)):
return source1 == source2 && destination1 == destination2
case (.Heavyweight(let source1, let destination1), .Heavyweight(let source2, let destination2)):
return source1 == source2 && destination1 == destination2
default:
return false
}
}