mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-24 02:11:12 +01:00
Swift 4 support
This commit is contained in:
@@ -203,10 +203,10 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
|
||||
self.isCommitted = true
|
||||
let group = DispatchGroup()
|
||||
group.enter()
|
||||
self.context.saveAsynchronouslyWithCompletion { (result) -> Void in
|
||||
self.context.saveAsynchronouslyWithCompletion { (hasChanges, error) -> Void in
|
||||
|
||||
completion(result.0, result.1)
|
||||
self.result = result
|
||||
completion(hasChanges, error)
|
||||
self.result = (hasChanges, error)
|
||||
group.leave()
|
||||
}
|
||||
group.wait()
|
||||
@@ -226,12 +226,15 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
|
||||
!self.isCommitted,
|
||||
"Attempted to commit a \(cs_typeName(self)) more than once."
|
||||
)
|
||||
self.autoCommit { (result) in
|
||||
self.autoCommit { (hasChanges, error) in
|
||||
|
||||
switch result {
|
||||
if let error = error {
|
||||
|
||||
case (let hasChanges, nil): completion(SaveResult(hasChanges: hasChanges))
|
||||
case (_, let error?): completion(SaveResult(error))
|
||||
completion(SaveResult(error))
|
||||
}
|
||||
else {
|
||||
|
||||
completion(SaveResult(hasChanges: hasChanges))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,12 +54,15 @@ public final class CSAsynchronousDataTransaction: CSBaseDataTransaction, CoreSto
|
||||
!self.bridgeToSwift.isCommitted,
|
||||
"Attempted to commit a \(cs_typeName(self)) more than once."
|
||||
)
|
||||
self.bridgeToSwift.autoCommit { (result) in
|
||||
self.bridgeToSwift.autoCommit { (_, error) in
|
||||
|
||||
switch result {
|
||||
if let error = error {
|
||||
|
||||
case (_, nil): success?()
|
||||
case (_, let error?): failure?(error.bridgeToObjectiveC)
|
||||
failure?(error.bridgeToObjectiveC)
|
||||
}
|
||||
else {
|
||||
|
||||
success?()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,6 +218,7 @@ public final class CSSelect: NSObject {
|
||||
```
|
||||
- parameter numberTerm: the `CSSelectTerm` specifying the attribute/aggregate value to query
|
||||
*/
|
||||
@objc
|
||||
public convenience init(numberTerm: CSSelectTerm) {
|
||||
|
||||
self.init(Select<NSNumber>(numberTerm.bridgeToSwift))
|
||||
@@ -233,6 +234,7 @@ public final class CSSelect: NSObject {
|
||||
```
|
||||
- parameter decimalTerm: the `CSSelectTerm` specifying the attribute/aggregate value to query
|
||||
*/
|
||||
@objc
|
||||
public convenience init(decimalTerm: CSSelectTerm) {
|
||||
|
||||
self.init(Select<NSDecimalNumber>(decimalTerm.bridgeToSwift))
|
||||
@@ -248,6 +250,7 @@ public final class CSSelect: NSObject {
|
||||
```
|
||||
- parameter stringTerm: the `CSSelectTerm` specifying the attribute/aggregate value to query
|
||||
*/
|
||||
@objc
|
||||
public convenience init(stringTerm: CSSelectTerm) {
|
||||
|
||||
self.init(Select<NSString>(stringTerm.bridgeToSwift))
|
||||
@@ -263,6 +266,7 @@ public final class CSSelect: NSObject {
|
||||
```
|
||||
- parameter dateTerm: the `CSSelectTerm` specifying the attribute/aggregate value to query
|
||||
*/
|
||||
@objc
|
||||
public convenience init(dateTerm: CSSelectTerm) {
|
||||
|
||||
self.init(Select<Date>(dateTerm.bridgeToSwift))
|
||||
@@ -278,6 +282,7 @@ public final class CSSelect: NSObject {
|
||||
```
|
||||
- parameter dataTerm: the `CSSelectTerm` specifying the attribute/aggregate value to query
|
||||
*/
|
||||
@objc
|
||||
public convenience init(dataTerm: CSSelectTerm) {
|
||||
|
||||
self.init(Select<Data>(dataTerm.bridgeToSwift))
|
||||
@@ -292,6 +297,7 @@ public final class CSSelect: NSObject {
|
||||
// ...
|
||||
```
|
||||
*/
|
||||
@objc
|
||||
public convenience init(objectIDTerm: ()) {
|
||||
|
||||
self.init(Select<NSManagedObjectID>(.objectID()))
|
||||
@@ -307,6 +313,7 @@ public final class CSSelect: NSObject {
|
||||
- parameter term: the `CSSelectTerm` specifying the attribute/aggregate value to query
|
||||
- returns: a `CSSelect` clause for querying an entity attribute
|
||||
*/
|
||||
@objc
|
||||
public static func dictionaryForTerm(_ term: CSSelectTerm) -> CSSelect {
|
||||
|
||||
return self.init(Select<NSDictionary>(term.bridgeToSwift))
|
||||
@@ -325,6 +332,7 @@ public final class CSSelect: NSObject {
|
||||
- parameter terms: the `CSSelectTerm`s specifying the attribute/aggregate values to query
|
||||
- returns: a `CSSelect` clause for querying an entity attribute
|
||||
*/
|
||||
@objc
|
||||
public static func dictionaryForTerms(_ terms: [CSSelectTerm]) -> CSSelect {
|
||||
|
||||
return self.init(Select<NSDictionary>(terms.map { $0.bridgeToSwift }))
|
||||
|
||||
@@ -281,7 +281,7 @@ public final class CoreStoreSchema: DynamicSchema {
|
||||
case let attribute as AttributeProtocol:
|
||||
let description = NSAttributeDescription()
|
||||
description.name = attribute.keyPath
|
||||
description.attributeType = type(of: attribute).attributeType
|
||||
description.attributeType = Swift.type(of: attribute).attributeType
|
||||
description.isOptional = attribute.isOptional
|
||||
description.isIndexed = attribute.isIndexed
|
||||
description.defaultValue = attribute.defaultValue
|
||||
|
||||
@@ -647,8 +647,9 @@ public extension DataStack {
|
||||
let mappingProviders = storage.migrationMappingProviders
|
||||
do {
|
||||
|
||||
try withExtendedLifetime((sourceSchema.rawModel(), destinationSchema.rawModel())) { (sourceModel, destinationModel) in
|
||||
try withExtendedLifetime((sourceSchema.rawModel(), destinationSchema.rawModel())) {
|
||||
|
||||
let (sourceModel, destinationModel) = $0
|
||||
let mapping = try mappingProviders.findMapping(
|
||||
sourceSchema: sourceSchema,
|
||||
destinationSchema: destinationSchema,
|
||||
|
||||
@@ -117,8 +117,9 @@ public struct MigrationChain: ExpressibleByNilLiteral, ExpressibleByStringLitera
|
||||
|
||||
var isValid = true
|
||||
var versionTree = [String: String]()
|
||||
elements.forEach { (sourceVersion, destinationVersion) in
|
||||
elements.forEach {
|
||||
|
||||
let (sourceVersion, destinationVersion) = $0
|
||||
guard let _ = versionTree.updateValue(destinationVersion, forKey: sourceVersion) else {
|
||||
|
||||
return
|
||||
@@ -130,8 +131,8 @@ public struct MigrationChain: ExpressibleByNilLiteral, ExpressibleByStringLitera
|
||||
}
|
||||
let leafVersions = Set(
|
||||
elements
|
||||
.filter { versionTree[$1] == nil }
|
||||
.map { $1 }
|
||||
.filter { versionTree[$0.1] == nil }
|
||||
.map { $0.1 }
|
||||
)
|
||||
|
||||
let isVersionAmbiguous = { (start: String) -> Bool in
|
||||
|
||||
@@ -179,7 +179,7 @@ internal extension NSManagedObjectContext {
|
||||
}
|
||||
|
||||
@nonobjc
|
||||
internal func saveAsynchronouslyWithCompletion(_ completion: @escaping (_ hasChanges: Bool, _ error: CoreStoreError?) -> Void = { _ in }) {
|
||||
internal func saveAsynchronouslyWithCompletion(_ completion: @escaping (_ hasChanges: Bool, _ error: CoreStoreError?) -> Void = { (_, _) in }) {
|
||||
|
||||
self.perform {
|
||||
|
||||
|
||||
@@ -342,6 +342,7 @@ extension NSData: QueryableAttributeType {
|
||||
|
||||
public typealias QueryableNativeType = NSData
|
||||
|
||||
@nonobjc
|
||||
public class var cs_rawAttributeType: NSAttributeType {
|
||||
|
||||
return .binaryDataAttributeType
|
||||
@@ -372,6 +373,7 @@ extension NSDate: QueryableAttributeType {
|
||||
|
||||
public typealias QueryableNativeType = NSDate
|
||||
|
||||
@nonobjc
|
||||
public class var cs_rawAttributeType: NSAttributeType {
|
||||
|
||||
return .dateAttributeType
|
||||
@@ -413,6 +415,7 @@ extension NSManagedObjectID: QueryableAttributeType {
|
||||
|
||||
public typealias QueryableNativeType = NSManagedObjectID
|
||||
|
||||
@nonobjc
|
||||
public class var cs_rawAttributeType: NSAttributeType {
|
||||
|
||||
return .objectIDAttributeType
|
||||
@@ -443,6 +446,7 @@ extension NSNull: QueryableAttributeType {
|
||||
|
||||
public typealias QueryableNativeType = NSNull
|
||||
|
||||
@nonobjc
|
||||
public class var cs_rawAttributeType: NSAttributeType {
|
||||
|
||||
return .undefinedAttributeType
|
||||
@@ -473,6 +477,7 @@ extension NSNumber: QueryableAttributeType {
|
||||
|
||||
public typealias QueryableNativeType = NSNumber
|
||||
|
||||
@objc
|
||||
public class var cs_rawAttributeType: NSAttributeType {
|
||||
|
||||
return .integer64AttributeType
|
||||
@@ -503,6 +508,7 @@ extension NSString: QueryableAttributeType {
|
||||
|
||||
public typealias QueryableNativeType = NSString
|
||||
|
||||
@nonobjc
|
||||
public class var cs_rawAttributeType: NSAttributeType {
|
||||
|
||||
return .stringAttributeType
|
||||
@@ -533,6 +539,7 @@ extension NSURL: QueryableAttributeType {
|
||||
|
||||
public typealias QueryableNativeType = NSString
|
||||
|
||||
@nonobjc
|
||||
public class var cs_rawAttributeType: NSAttributeType {
|
||||
|
||||
return .stringAttributeType
|
||||
@@ -558,6 +565,7 @@ extension NSUUID: QueryableAttributeType {
|
||||
|
||||
public typealias QueryableNativeType = NSString
|
||||
|
||||
@nonobjc
|
||||
public class var cs_rawAttributeType: NSAttributeType {
|
||||
|
||||
return .stringAttributeType
|
||||
|
||||
Reference in New Issue
Block a user