From 5431e2e97439e5830b8bf3917d5e2cfeb5a82f19 Mon Sep 17 00:00:00 2001 From: John Rommel Estropia Date: Sat, 10 Mar 2018 21:07:53 +0900 Subject: [PATCH] Swift 4.1 support --- CoreStore.xcodeproj/project.pbxproj | 6 +++++- .../xcshareddata/xcschemes/CoreStore OSX.xcscheme | 4 +--- .../xcshareddata/xcschemes/CoreStore iOS.xcscheme | 4 +--- .../xcshareddata/xcschemes/CoreStore tvOS.xcscheme | 4 +--- .../xcschemes/CoreStore watchOS.xcscheme | 4 +--- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ .../CoreStoreDemo.xcodeproj/project.pbxproj | 6 +++++- .../xcshareddata/xcschemes/CoreStoreDemo.xcscheme | 4 +--- .../ObjectObserverDemoViewController.swift | 6 +++--- Sources/AsynchronousDataTransaction.swift | 2 +- Sources/AttributeProtocol.swift | 2 +- Sources/BaseDataTransaction+Importing.swift | 4 ++-- Sources/BaseDataTransaction.swift | 14 +++++++------- Sources/CoreStoreError.swift | 2 +- Sources/CustomSchemaMappingProvider.swift | 4 ++-- Sources/NSManagedObjectContext+Querying.swift | 4 ++-- Sources/Relationship.swift | 4 ++-- Sources/RelationshipProtocol.swift | 2 +- Sources/SynchronousDataTransaction.swift | 2 +- 19 files changed, 46 insertions(+), 40 deletions(-) create mode 100644 CoreStore.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/CoreStore.xcodeproj/project.pbxproj b/CoreStore.xcodeproj/project.pbxproj index 480a76c..7601749 100644 --- a/CoreStore.xcodeproj/project.pbxproj +++ b/CoreStore.xcodeproj/project.pbxproj @@ -1754,7 +1754,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0730; - LastUpgradeCheck = 0900; + LastUpgradeCheck = 0930; ORGANIZATIONNAME = "John Rommel Estropia"; TargetAttributes = { 2F03A52F19C5C6DA005002A5 = { @@ -2648,6 +2648,7 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; @@ -2655,6 +2656,7 @@ CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -2715,6 +2717,7 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; @@ -2722,6 +2725,7 @@ CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; diff --git a/CoreStore.xcodeproj/xcshareddata/xcschemes/CoreStore OSX.xcscheme b/CoreStore.xcodeproj/xcshareddata/xcschemes/CoreStore OSX.xcscheme index 0fdbcb1..636aef6 100644 --- a/CoreStore.xcodeproj/xcshareddata/xcschemes/CoreStore OSX.xcscheme +++ b/CoreStore.xcodeproj/xcshareddata/xcschemes/CoreStore OSX.xcscheme @@ -1,6 +1,6 @@ @@ -37,7 +36,6 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/CoreStore.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/CoreStore.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/CoreStore.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/CoreStoreDemo/CoreStoreDemo.xcodeproj/project.pbxproj b/CoreStoreDemo/CoreStoreDemo.xcodeproj/project.pbxproj index d0deb97..7bb6714 100644 --- a/CoreStoreDemo/CoreStoreDemo.xcodeproj/project.pbxproj +++ b/CoreStoreDemo/CoreStoreDemo.xcodeproj/project.pbxproj @@ -265,7 +265,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0900; + LastUpgradeCheck = 0930; ORGANIZATIONNAME = "John Rommel Estropia"; TargetAttributes = { B54AAD481AF4D26E00848AE0 = { @@ -375,12 +375,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -430,12 +432,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; diff --git a/CoreStoreDemo/CoreStoreDemo.xcodeproj/xcshareddata/xcschemes/CoreStoreDemo.xcscheme b/CoreStoreDemo/CoreStoreDemo.xcodeproj/xcshareddata/xcschemes/CoreStoreDemo.xcscheme index e9e5323..3888de1 100644 --- a/CoreStoreDemo/CoreStoreDemo.xcodeproj/xcshareddata/xcschemes/CoreStoreDemo.xcscheme +++ b/CoreStoreDemo/CoreStoreDemo.xcodeproj/xcshareddata/xcschemes/CoreStoreDemo.xcscheme @@ -1,6 +1,6 @@ @@ -46,7 +45,6 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/ObjectObserverDemoViewController.swift b/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/ObjectObserverDemoViewController.swift index 059c735..2047ff2 100644 --- a/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/ObjectObserverDemoViewController.swift +++ b/CoreStoreDemo/CoreStoreDemo/List and Object Observers Demo/ObjectObserverDemoViewController.swift @@ -184,15 +184,15 @@ class ObjectObserverDemoViewController: UIViewController, ObjectObserver { self.hsbLabel?.text = palette.colorText - if changedKeys == nil || changedKeys?.contains(Palette.keyPath{ $0.hue }) == true { + if changedKeys == nil || changedKeys?.contains(String(keyPath: \Palette.hue)) == true { self.hueSlider?.value = Float(palette.hue.value) } - if changedKeys == nil || changedKeys?.contains(Palette.keyPath{ $0.saturation }) == true { + if changedKeys == nil || changedKeys?.contains(String(keyPath: \Palette.saturation)) == true { self.saturationSlider?.value = palette.saturation.value } - if changedKeys == nil || changedKeys?.contains(Palette.keyPath{ $0.brightness }) == true { + if changedKeys == nil || changedKeys?.contains(String(keyPath: \Palette.hue)) == true { self.brightnessSlider?.value = palette.brightness.value } diff --git a/Sources/AsynchronousDataTransaction.swift b/Sources/AsynchronousDataTransaction.swift index c3601d4..a598e03 100644 --- a/Sources/AsynchronousDataTransaction.swift +++ b/Sources/AsynchronousDataTransaction.swift @@ -172,7 +172,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction { "Attempted to delete an entities from an already committed \(cs_typeName(self))." ) - super.delete(([object1, object2] + objects).flatMap { $0 }) + super.delete(([object1, object2] + objects).compactMap { $0 }) } /** diff --git a/Sources/AttributeProtocol.swift b/Sources/AttributeProtocol.swift index 4bc91bb..a0ed0f7 100644 --- a/Sources/AttributeProtocol.swift +++ b/Sources/AttributeProtocol.swift @@ -41,7 +41,7 @@ internal protocol AttributeProtocol: class { var renamingIdentifier: () -> String? { get } var defaultValue: () -> Any? { get } var affectedByKeyPaths: () -> Set { get } - weak var parentObject: CoreStoreObject? { get set } + var parentObject: CoreStoreObject? { get set } var getter: CoreStoreManagedObject.CustomGetter? { get } var setter: CoreStoreManagedObject.CustomSetter? { get } } diff --git a/Sources/BaseDataTransaction+Importing.swift b/Sources/BaseDataTransaction+Importing.swift index 4905fa5..1c4955d 100644 --- a/Sources/BaseDataTransaction+Importing.swift +++ b/Sources/BaseDataTransaction+Importing.swift @@ -108,7 +108,7 @@ public extension BaseDataTransaction { return try autoreleasepool { - return try sourceArray.flatMap { (source) -> D? in + return try sourceArray.compactMap { (source) -> D? in let entityType = into.entityClass guard entityType.shouldInsert(from: source, in: self) else { @@ -201,7 +201,7 @@ public extension BaseDataTransaction { var importSourceByID = Dictionary() let sortedIDs = try autoreleasepool { - return try sourceArray.flatMap { (source) -> D.UniqueIDType? in + return try sourceArray.compactMap { (source) -> D.UniqueIDType? in guard let uniqueIDValue = try entityType.uniqueID(from: source, in: self) else { diff --git a/Sources/BaseDataTransaction.swift b/Sources/BaseDataTransaction.swift index 0c75700..ada259a 100644 --- a/Sources/BaseDataTransaction.swift +++ b/Sources/BaseDataTransaction.swift @@ -181,7 +181,7 @@ public /*abstract*/ class BaseDataTransaction { */ public func delete(_ object1: D?, _ object2: D?, _ objects: D?...) { - self.delete(([object1, object2] + objects).flatMap { $0 }) + self.delete(([object1, object2] + objects).compactMap { $0 }) } /** @@ -230,7 +230,7 @@ public /*abstract*/ class BaseDataTransaction { !self.isCommitted, "Attempted to access inserted objects from an already committed \(cs_typeName(self))." ) - return Set(self.context.insertedObjects.flatMap({ entity.cs_matches(object: $0) ? entity.cs_fromRaw(object: $0) : nil })) + return Set(self.context.insertedObjects.compactMap({ entity.cs_matches(object: $0) ? entity.cs_fromRaw(object: $0) : nil })) } /** @@ -267,7 +267,7 @@ public /*abstract*/ class BaseDataTransaction { !self.isCommitted, "Attempted to access inserted objects IDs from an already committed \(cs_typeName(self))." ) - return Set(self.context.insertedObjects.flatMap({ entity.cs_matches(object: $0) ? $0.objectID : nil })) + return Set(self.context.insertedObjects.compactMap({ entity.cs_matches(object: $0) ? $0.objectID : nil })) } /** @@ -286,7 +286,7 @@ public /*abstract*/ class BaseDataTransaction { !self.isCommitted, "Attempted to access updated objects from an already committed \(cs_typeName(self))." ) - return Set(self.context.updatedObjects.flatMap({ entity.cs_matches(object: $0) ? entity.cs_fromRaw(object: $0) : nil })) + return Set(self.context.updatedObjects.compactMap({ entity.cs_matches(object: $0) ? entity.cs_fromRaw(object: $0) : nil })) } /** @@ -323,7 +323,7 @@ public /*abstract*/ class BaseDataTransaction { !self.isCommitted, "Attempted to access updated object IDs from an already committed \(cs_typeName(self))." ) - return Set(self.context.updatedObjects.flatMap({ entity.cs_matches(object: $0) ? $0.objectID : nil })) + return Set(self.context.updatedObjects.compactMap({ entity.cs_matches(object: $0) ? $0.objectID : nil })) } /** @@ -342,7 +342,7 @@ public /*abstract*/ class BaseDataTransaction { !self.isCommitted, "Attempted to access deleted objects from an already committed \(cs_typeName(self))." ) - return Set(self.context.deletedObjects.flatMap({ entity.cs_matches(object: $0) ? entity.cs_fromRaw(object: $0) : nil })) + return Set(self.context.deletedObjects.compactMap({ entity.cs_matches(object: $0) ? entity.cs_fromRaw(object: $0) : nil })) } /** @@ -380,7 +380,7 @@ public /*abstract*/ class BaseDataTransaction { !self.isCommitted, "Attempted to access deleted object IDs from an already committed \(cs_typeName(self))." ) - return Set(self.context.deletedObjects.flatMap({ entity.cs_matches(object: $0) ? $0.objectID : nil })) + return Set(self.context.deletedObjects.compactMap({ entity.cs_matches(object: $0) ? $0.objectID : nil })) } diff --git a/Sources/CoreStoreError.swift b/Sources/CoreStoreError.swift index 3ec6c42..6138112 100644 --- a/Sources/CoreStoreError.swift +++ b/Sources/CoreStoreError.swift @@ -282,7 +282,7 @@ public enum CoreStoreErrorCode: Int { // MARK: - NSError -public extension NSError { +internal extension NSError { // MARK: Internal diff --git a/Sources/CustomSchemaMappingProvider.swift b/Sources/CustomSchemaMappingProvider.swift index e028433..7bc43a8 100644 --- a/Sources/CustomSchemaMappingProvider.swift +++ b/Sources/CustomSchemaMappingProvider.swift @@ -56,8 +56,8 @@ public class CustomSchemaMappingProvider: Hashable, SchemaMappingProvider { CoreStore.assert( cs_lazy { - let sources = entityMappings.flatMap({ $0.entityMappingSourceEntity }) - let destinations = entityMappings.flatMap({ $0.entityMappingDestinationEntity }) + let sources = entityMappings.compactMap({ $0.entityMappingSourceEntity }) + let destinations = entityMappings.compactMap({ $0.entityMappingDestinationEntity }) return sources.count == Set(sources).count && destinations.count == Set(destinations).count }, diff --git a/Sources/NSManagedObjectContext+Querying.swift b/Sources/NSManagedObjectContext+Querying.swift index 706c07b..ca2eb6c 100644 --- a/Sources/NSManagedObjectContext+Querying.swift +++ b/Sources/NSManagedObjectContext+Querying.swift @@ -91,13 +91,13 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource { @nonobjc public func fetchExisting(_ objects: S) -> [D] where S.Iterator.Element == D { - return objects.flatMap({ self.fetchExisting($0.cs_id()) }) + return objects.compactMap({ self.fetchExisting($0.cs_id()) }) } @nonobjc public func fetchExisting(_ objectIDs: S) -> [D] where S.Iterator.Element == NSManagedObjectID { - return objectIDs.flatMap({ self.fetchExisting($0) }) + return objectIDs.compactMap({ self.fetchExisting($0) }) } @nonobjc diff --git a/Sources/Relationship.swift b/Sources/Relationship.swift index f80269d..e066fd4 100644 --- a/Sources/Relationship.swift +++ b/Sources/Relationship.swift @@ -1071,7 +1071,7 @@ extension RelationshipContainer.ToManyOrdered { return relationship.nativeValue.elementsEqual( collection.lazy.map({ $0.rawObject! }), - by: { ($0 as! NSManagedObject) == ($1 as! NSManagedObject) } + by: { ($0 as! NSManagedObject) == $1 } ) } @@ -1089,7 +1089,7 @@ extension RelationshipContainer.ToManyOrdered { return relationship.nativeValue.elementsEqual( collection.lazy.map({ $0.rawObject! }), - by: { ($0 as! NSManagedObject) == ($1 as! NSManagedObject) } + by: { ($0 as! NSManagedObject) == $1 } ) } diff --git a/Sources/RelationshipProtocol.swift b/Sources/RelationshipProtocol.swift index aa401ea..7253728 100644 --- a/Sources/RelationshipProtocol.swift +++ b/Sources/RelationshipProtocol.swift @@ -37,7 +37,7 @@ internal protocol RelationshipProtocol: class { var deleteRule: NSDeleteRule { get } var inverse: (type: CoreStoreObject.Type, keyPath: () -> KeyPathString?) { get } var affectedByKeyPaths: () -> Set { get } - weak var parentObject: CoreStoreObject? { get set } + var parentObject: CoreStoreObject? { get set } var versionHashModifier: () -> String? { get } var renamingIdentifier: () -> String? { get } var minCount: Int { get } diff --git a/Sources/SynchronousDataTransaction.swift b/Sources/SynchronousDataTransaction.swift index 8176dfd..eed0e6b 100644 --- a/Sources/SynchronousDataTransaction.swift +++ b/Sources/SynchronousDataTransaction.swift @@ -127,7 +127,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction { "Attempted to delete an entities from an already committed \(cs_typeName(self))." ) - super.delete(([object1, object2] + objects).flatMap { $0 }) + super.delete(([object1, object2] + objects).compactMap { $0 }) } /**