From 4beb11519ef463bae77fe13633891233d21aa683 Mon Sep 17 00:00:00 2001 From: John Estropia Date: Wed, 8 Jan 2020 10:26:27 +0900 Subject: [PATCH] Deprecation of ObjectiveC shivs --- CoreStoreTests/BridgingTests.m | 6 ++++ CoreStoreTests/ErrorTests.swift | 1 + Sources/CSAsynchronousDataTransaction.swift | 2 ++ Sources/CSDataStack+Migrating.swift | 1 + Sources/CSDataStack+Observing.swift | 1 + Sources/CSDataStack+Querying.swift | 1 + Sources/CSDataStack+Transaction.swift | 1 + Sources/CSDataStack.swift | 2 ++ Sources/CSError.swift | 38 ++++++++++++--------- Sources/CSInMemoryStore.swift | 2 ++ Sources/CSMigrationResult.swift | 2 ++ Sources/CSMigrationType.swift | 2 ++ Sources/CSSQliteStore.swift | 2 ++ Sources/CSSetupResult.swift | 2 ++ Sources/CSSynchronousDataTransaction.swift | 2 ++ Sources/CSTweak.swift | 2 ++ Sources/CSUnsafeDataModelSchema.swift | 2 ++ Sources/CSUnsafeDataTransaction.swift | 2 ++ Sources/CSXcodeDataModelSchema.swift | 2 ++ Sources/CoreStoreBridge.h | 2 +- Sources/CoreStoreBridge.swift | 11 ++++++ 21 files changed, 69 insertions(+), 17 deletions(-) diff --git a/CoreStoreTests/BridgingTests.m b/CoreStoreTests/BridgingTests.m index 8ed7650..853db4e 100644 --- a/CoreStoreTests/BridgingTests.m +++ b/CoreStoreTests/BridgingTests.m @@ -30,6 +30,10 @@ @import CoreData; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + + // MARK: - BridgingTests @implementation BridgingTests @@ -261,3 +265,5 @@ } @end + +#pragma clang diagnostic pop diff --git a/CoreStoreTests/ErrorTests.swift b/CoreStoreTests/ErrorTests.swift index 14870b7..35f8527 100644 --- a/CoreStoreTests/ErrorTests.swift +++ b/CoreStoreTests/ErrorTests.swift @@ -31,6 +31,7 @@ import CoreStore // MARK: - ErrorTests +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") final class ErrorTests: XCTestCase { @objc diff --git a/Sources/CSAsynchronousDataTransaction.swift b/Sources/CSAsynchronousDataTransaction.swift index 4bd3850..9e39fb3 100644 --- a/Sources/CSAsynchronousDataTransaction.swift +++ b/Sources/CSAsynchronousDataTransaction.swift @@ -34,6 +34,7 @@ import CoreData - SeeAlso: `AsynchronousDataTransaction` */ +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") @objc public final class CSAsynchronousDataTransaction: CSBaseDataTransaction, CoreStoreObjectiveCType { @@ -161,6 +162,7 @@ public final class CSAsynchronousDataTransaction: CSBaseDataTransaction, CoreSto // MARK: - AsynchronousDataTransaction +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") extension AsynchronousDataTransaction: CoreStoreSwiftType { // MARK: CoreStoreSwiftType diff --git a/Sources/CSDataStack+Migrating.swift b/Sources/CSDataStack+Migrating.swift index 0c4e307..b3e95f2 100644 --- a/Sources/CSDataStack+Migrating.swift +++ b/Sources/CSDataStack+Migrating.swift @@ -29,6 +29,7 @@ import CoreData // MARK: - CSDataStack +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") extension CSDataStack { /** diff --git a/Sources/CSDataStack+Observing.swift b/Sources/CSDataStack+Observing.swift index 7f97735..78c0141 100644 --- a/Sources/CSDataStack+Observing.swift +++ b/Sources/CSDataStack+Observing.swift @@ -29,6 +29,7 @@ import CoreData // MARK: - CSDataStack +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") @available(macOS 10.12, *) extension CSDataStack { diff --git a/Sources/CSDataStack+Querying.swift b/Sources/CSDataStack+Querying.swift index 29ef10a..1c1a440 100644 --- a/Sources/CSDataStack+Querying.swift +++ b/Sources/CSDataStack+Querying.swift @@ -29,6 +29,7 @@ import CoreData // MARK: - CSDataStack +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") extension CSDataStack { /** diff --git a/Sources/CSDataStack+Transaction.swift b/Sources/CSDataStack+Transaction.swift index 1965705..e652e33 100644 --- a/Sources/CSDataStack+Transaction.swift +++ b/Sources/CSDataStack+Transaction.swift @@ -28,6 +28,7 @@ import Foundation // MARK: - CSDataStack +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") extension CSDataStack { /** diff --git a/Sources/CSDataStack.swift b/Sources/CSDataStack.swift index dd659fd..d4878a1 100644 --- a/Sources/CSDataStack.swift +++ b/Sources/CSDataStack.swift @@ -34,6 +34,7 @@ import CoreData - SeeAlso: `DataStack` */ +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") @objc public final class CSDataStack: NSObject, CoreStoreObjectiveCType { @@ -209,6 +210,7 @@ public final class CSDataStack: NSObject, CoreStoreObjectiveCType { // MARK: - DataStack +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") extension DataStack: CoreStoreSwiftType { // MARK: CoreStoreSwiftType diff --git a/Sources/CSError.swift b/Sources/CSError.swift index 8ee149b..b250245 100644 --- a/Sources/CSError.swift +++ b/Sources/CSError.swift @@ -35,7 +35,7 @@ import CoreData - SeeAlso: `CoreStoreError` */ @objc -public final class CSError: NSError, CoreStoreObjectiveCType { +public final class CSError: NSError { /** The `NSError` error domain for `CSError`. @@ -67,20 +67,6 @@ public final class CSError: NSError, CoreStoreObjectiveCType { return "(\(String(reflecting: Self.self))) \(self.bridgeToSwift.coreStoreDumpString)" } - - // MARK: CoreStoreObjectiveCType - - public var bridgeToSwift: CoreStoreError { - - if let swift = self.swiftError { - - return swift - } - let swift = CoreStoreError(_bridgedNSError: self) ?? .unknown - self.swiftError = swift - return swift - } - /** Do not call directly! */ @@ -101,6 +87,23 @@ public final class CSError: NSError, CoreStoreObjectiveCType { private var swiftError: CoreStoreError? } +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") +extension CSError: CoreStoreObjectiveCType { + + // MARK: CoreStoreObjectiveCType + + public var bridgeToSwift: CoreStoreError { + + if let swift = self.swiftError { + + return swift + } + let swift = CoreStoreError(_bridgedNSError: self) ?? .unknown + self.swiftError = swift + return swift + } +} + // MARK: - CSErrorCode @@ -110,6 +113,7 @@ public final class CSError: NSError, CoreStoreObjectiveCType { - SeeAlso: `CSError` - SeeAlso: `CoreStoreError` */ +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") @objc public enum CSErrorCode: Int { @@ -152,6 +156,7 @@ public enum CSErrorCode: Int { // MARK: - CoreStoreError +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") extension CoreStoreError: CoreStoreSwiftType, _ObjectiveCBridgeableError { // MARK: CoreStoreSwiftType @@ -281,7 +286,8 @@ extension Error { return .unknown } } - + + @available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") internal var bridgeToObjectiveC: NSError { switch self { diff --git a/Sources/CSInMemoryStore.swift b/Sources/CSInMemoryStore.swift index 341dc45..440c56d 100644 --- a/Sources/CSInMemoryStore.swift +++ b/Sources/CSInMemoryStore.swift @@ -34,6 +34,7 @@ import CoreData - SeeAlso: `InMemoryStore` */ +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") @objc public final class CSInMemoryStore: NSObject, CSStorageInterface, CoreStoreObjectiveCType { @@ -121,6 +122,7 @@ public final class CSInMemoryStore: NSObject, CSStorageInterface, CoreStoreObjec // MARK: - InMemoryStore +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") extension InMemoryStore: CoreStoreSwiftType { // MARK: CoreStoreSwiftType diff --git a/Sources/CSMigrationResult.swift b/Sources/CSMigrationResult.swift index c3e1cb0..54cea1e 100644 --- a/Sources/CSMigrationResult.swift +++ b/Sources/CSMigrationResult.swift @@ -34,6 +34,7 @@ import CoreData - SeeAlso: `MigrationResult` */ +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") @objc public final class CSMigrationResult: NSObject, CoreStoreObjectiveCType { @@ -173,6 +174,7 @@ public final class CSMigrationResult: NSObject, CoreStoreObjectiveCType { // MARK: - MigrationResult +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") extension MigrationResult { // MARK: CoreStoreSwiftType diff --git a/Sources/CSMigrationType.swift b/Sources/CSMigrationType.swift index c643856..9669c32 100644 --- a/Sources/CSMigrationType.swift +++ b/Sources/CSMigrationType.swift @@ -34,6 +34,7 @@ import CoreData - SeeAlso: `MigrationType` */ +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") @objc public final class CSMigrationType: NSObject, CoreStoreObjectiveCType { @@ -119,6 +120,7 @@ public final class CSMigrationType: NSObject, CoreStoreObjectiveCType { // MARK: - MigrationType +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") extension MigrationType: CoreStoreSwiftType { // MARK: CoreStoreSwiftType diff --git a/Sources/CSSQliteStore.swift b/Sources/CSSQliteStore.swift index 4611b6b..b786bf3 100644 --- a/Sources/CSSQliteStore.swift +++ b/Sources/CSSQliteStore.swift @@ -34,6 +34,7 @@ import CoreData - SeeAlso: `SQLiteStore` */ +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") @objc public final class CSSQLiteStore: NSObject, CSLocalStorage, CoreStoreObjectiveCType { @@ -196,6 +197,7 @@ public final class CSSQLiteStore: NSObject, CSLocalStorage, CoreStoreObjectiveCT // MARK: - SQLiteStore +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") extension SQLiteStore: CoreStoreSwiftType { // MARK: CoreStoreSwiftType diff --git a/Sources/CSSetupResult.swift b/Sources/CSSetupResult.swift index 1e66b13..cf5e788 100644 --- a/Sources/CSSetupResult.swift +++ b/Sources/CSSetupResult.swift @@ -34,6 +34,7 @@ import CoreData - SeeAlso: `SetupResult` */ +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") @objc public final class CSSetupResult: NSObject { @@ -177,6 +178,7 @@ public final class CSSetupResult: NSObject { // MARK: - SetupResult +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") extension SetupResult where Success: StorageInterface, Success: CoreStoreSwiftType, Success.ObjectiveCType: CSStorageInterface, Failure == CoreStoreError { // MARK: CoreStoreSwiftType diff --git a/Sources/CSSynchronousDataTransaction.swift b/Sources/CSSynchronousDataTransaction.swift index 4874226..aef28cd 100644 --- a/Sources/CSSynchronousDataTransaction.swift +++ b/Sources/CSSynchronousDataTransaction.swift @@ -34,6 +34,7 @@ import CoreData - SeeAlso: `SynchronousDataTransaction` */ +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") @objc public final class CSSynchronousDataTransaction: CSBaseDataTransaction, CoreStoreObjectiveCType { @@ -148,6 +149,7 @@ public final class CSSynchronousDataTransaction: CSBaseDataTransaction, CoreStor // MARK: - SynchronousDataTransaction +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") extension SynchronousDataTransaction: CoreStoreSwiftType { // MARK: CoreStoreSwiftType diff --git a/Sources/CSTweak.swift b/Sources/CSTweak.swift index 39324c7..a852780 100644 --- a/Sources/CSTweak.swift +++ b/Sources/CSTweak.swift @@ -34,6 +34,7 @@ import CoreData - SeeAlso: `Tweak` */ +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") @objc public final class CSTweak: NSObject, CSFetchClause, CSQueryClause, CSDeleteClause, CoreStoreObjectiveCType { @@ -90,6 +91,7 @@ public final class CSTweak: NSObject, CSFetchClause, CSQueryClause, CSDeleteClau // MARK: - Tweak +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") extension Tweak: CoreStoreSwiftType { // MARK: CoreStoreSwiftType diff --git a/Sources/CSUnsafeDataModelSchema.swift b/Sources/CSUnsafeDataModelSchema.swift index 08552d6..f0a3a39 100644 --- a/Sources/CSUnsafeDataModelSchema.swift +++ b/Sources/CSUnsafeDataModelSchema.swift @@ -34,6 +34,7 @@ import Foundation - SeeAlso: `UnsafeDataModelSchema` */ +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") @objc public final class CSUnsafeDataModelSchema: NSObject, CSDynamicSchema, CoreStoreObjectiveCType { @@ -104,6 +105,7 @@ public final class CSUnsafeDataModelSchema: NSObject, CSDynamicSchema, CoreStore // MARK: - UnsafeDataModelSchema +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") extension UnsafeDataModelSchema: CoreStoreSwiftType { // MARK: CoreStoreSwiftType diff --git a/Sources/CSUnsafeDataTransaction.swift b/Sources/CSUnsafeDataTransaction.swift index 10b610c..236d7d2 100644 --- a/Sources/CSUnsafeDataTransaction.swift +++ b/Sources/CSUnsafeDataTransaction.swift @@ -34,6 +34,7 @@ import CoreData - SeeAlso: `UnsafeDataTransaction` */ +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") @objc public final class CSUnsafeDataTransaction: CSBaseDataTransaction, CoreStoreObjectiveCType { /** @@ -208,6 +209,7 @@ public final class CSUnsafeDataTransaction: CSBaseDataTransaction, CoreStoreObje // MARK: - UnsafeDataTransaction +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") extension UnsafeDataTransaction: CoreStoreSwiftType { // MARK: CoreStoreSwiftType diff --git a/Sources/CSXcodeDataModelSchema.swift b/Sources/CSXcodeDataModelSchema.swift index d630ae2..8b4f428 100644 --- a/Sources/CSXcodeDataModelSchema.swift +++ b/Sources/CSXcodeDataModelSchema.swift @@ -35,6 +35,7 @@ import Foundation - SeeAlso: `XcodeDataModelSchema` */ @objc +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") public final class CSXcodeDataModelSchema: NSObject, CSDynamicSchema, CoreStoreObjectiveCType { /** @@ -104,6 +105,7 @@ public final class CSXcodeDataModelSchema: NSObject, CSDynamicSchema, CoreStoreO // MARK: - XcodeDataModelSchema +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") extension XcodeDataModelSchema: CoreStoreSwiftType { // MARK: CoreStoreSwiftType diff --git a/Sources/CoreStoreBridge.h b/Sources/CoreStoreBridge.h index 6956619..e7a4715 100644 --- a/Sources/CoreStoreBridge.h +++ b/Sources/CoreStoreBridge.h @@ -37,7 +37,7 @@ #error CoreStore Objective-C utilities can only be used on platforms that support C function overloading #endif -#define CORESTORE_EXTERN extern +#define CORESTORE_EXTERN extern __deprecated_msg("CoreStore Objective-C API will be removed soon.") #define CORESTORE_OVERLOADABLE __attribute__((__overloadable__)) #define CORESTORE_REQUIRES_NIL_TERMINATION __attribute__((sentinel(0, 1))) #define CORESTORE_RETURNS_RETAINED __attribute__((ns_returns_retained)) diff --git a/Sources/CoreStoreBridge.swift b/Sources/CoreStoreBridge.swift index 1c8aae9..b2c1dfc 100644 --- a/Sources/CoreStoreBridge.swift +++ b/Sources/CoreStoreBridge.swift @@ -31,6 +31,7 @@ import Foundation /** `CoreStoreObjectiveCType`s are Objective-C accessible classes that represent CoreStore's Swift types. */ +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") public protocol CoreStoreObjectiveCType: AnyObject { /** @@ -55,6 +56,7 @@ public protocol CoreStoreObjectiveCType: AnyObject { /** `CoreStoreSwiftType`s are CoreStore's Swift types that are bridgeable to Objective-C. */ +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") public protocol CoreStoreSwiftType { /** @@ -71,21 +73,25 @@ public protocol CoreStoreSwiftType { // MARK: - Internal +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") internal func bridge(_ closure: () -> T) -> T.ObjectiveCType { return closure().bridgeToObjectiveC } +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") internal func bridge(_ closure: () -> [T]) -> [T.ObjectiveCType] { return closure().map { $0.bridgeToObjectiveC } } +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") internal func bridge(_ closure: () -> T?) -> T.ObjectiveCType? { return closure()?.bridgeToObjectiveC } +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") internal func bridge(_ closure: () throws -> T) throws -> T.ObjectiveCType { do { @@ -98,6 +104,7 @@ internal func bridge(_ closure: () throws -> T) throws -> } } +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") internal func bridge(_ closure: () throws -> Void) throws { do { @@ -110,6 +117,7 @@ internal func bridge(_ closure: () throws -> Void) throws { } } +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") internal func bridge(_ error: NSErrorPointer, _ closure: () throws -> T) -> T.ObjectiveCType? { do { @@ -125,6 +133,7 @@ internal func bridge(_ error: NSErrorPointer, _ closure: } } +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") internal func bridge(_ error: NSErrorPointer, _ closure: () throws -> Void) -> Bool { do { @@ -140,6 +149,7 @@ internal func bridge(_ error: NSErrorPointer, _ closure: () throws -> Void) -> B } } +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") internal func bridge(_ error: NSErrorPointer, _ closure: () throws -> T?) -> T? { do { @@ -155,6 +165,7 @@ internal func bridge(_ error: NSErrorPointer, _ closure: () throws -> T?) -> } } +@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.") internal func bridge(_ error: NSErrorPointer, _ closure: () throws -> [T]) -> [T.ObjectiveCType]? { do {