From 2863605d845cd9bb255ddd91f47f92717dec637f Mon Sep 17 00:00:00 2001 From: John Estropia Date: Wed, 23 Jan 2019 12:25:52 +0900 Subject: [PATCH] silence deprecation internal warnings --- ...reStore+CustomDebugStringConvertible.swift | 32 ---------- Sources/DynamicKeyPath.swift | 8 ++- Sources/ICloudStore.swift | 61 ++++++++++++++++++- Sources/ICloudStoreObserver.swift | 22 +------ Sources/NSManagedObjectContext+Setup.swift | 2 +- 5 files changed, 68 insertions(+), 57 deletions(-) diff --git a/Sources/CoreStore+CustomDebugStringConvertible.swift b/Sources/CoreStore+CustomDebugStringConvertible.swift index b94fe28..155b9d3 100644 --- a/Sources/CoreStore+CustomDebugStringConvertible.swift +++ b/Sources/CoreStore+CustomDebugStringConvertible.swift @@ -324,38 +324,6 @@ extension GroupBy: CustomDebugStringConvertible, CoreStoreDebugStringConvertible } -#if os(iOS) || os(macOS) - -// MARK: - ICloudStore - -@available(*, deprecated, message: "Please see the release notes and Core Data documentation.") -extension ICloudStore: CustomDebugStringConvertible, CoreStoreDebugStringConvertible { - - // MARK: CustomDebugStringConvertible - - public var debugDescription: String { - - return formattedDebugDescription(self) - } - - - // MARK: CoreStoreDebugStringConvertible - - public var coreStoreDumpString: String { - - return createFormattedString( - "(", ")", - ("configuration", self.configuration as Any), - ("storeOptions", self.storeOptions as Any), - ("cacheFileURL", self.cacheFileURL), - ("cloudStorageOptions", self.cloudStorageOptions) - ) - } -} - -#endif - - // MARK: - InMemoryStore extension InMemoryStore: CustomDebugStringConvertible, CoreStoreDebugStringConvertible { diff --git a/Sources/DynamicKeyPath.swift b/Sources/DynamicKeyPath.swift index 9edf2df..86f3919 100644 --- a/Sources/DynamicKeyPath.swift +++ b/Sources/DynamicKeyPath.swift @@ -86,8 +86,12 @@ public extension KeyPathString { // MARK: - KeyPath: DynamicKeyPath -// TODO: SE-0143 is not implemented: https://github.com/apple/swift-evolution/blob/master/proposals/0143-conditional-conformances.md -//extension KeyPath: DynamicKeyPath where Root: NSManagedObject, Value: ImportableAttributeType { +// TODO: SE-0143 (https://github.com/apple/swift-evolution/blob/master/proposals/0143-conditional-conformances.md) is implemented but multiple conformances for the same type currently cannot be declared. +//extension KeyPath: DynamicKeyPath where Root: NSManagedObject, Value: ImportableAttributeType +//extension KeyPath: DynamicKeyPath where Root: NSManagedObject, Value: ImportableAttributeType? +//extension KeyPath: DynamicKeyPath where Root: NSManagedObject, Value: NSManagedObject? +//extension KeyPath: DynamicKeyPath where Root: NSManagedObject, Value: NSSet +//extension KeyPath: DynamicKeyPath where Root: NSManagedObject, Value: NSOrderedSet extension KeyPath: DynamicKeyPath { public typealias ObjectType = Root diff --git a/Sources/ICloudStore.swift b/Sources/ICloudStore.swift index 7d06eb1..de6bbb4 100644 --- a/Sources/ICloudStore.swift +++ b/Sources/ICloudStore.swift @@ -35,7 +35,7 @@ import CoreData A storage interface backed by an SQLite database managed by iCloud. */ @available(*, deprecated, message: "Please see the release notes and Core Data documentation.") -public final class ICloudStore: CloudStorage { +public final class ICloudStore: CloudStorage, CustomDebugStringConvertible, CoreStoreDebugStringConvertible { /** Initializes an iCloud store interface from the given ubiquitous store information. Returns `nil` if the container could not be located or if iCloud storage is unavailable for the current user or device @@ -447,6 +447,65 @@ public final class ICloudStore: CloudStorage { ) } } + + + // MARK: CustomDebugStringConvertible + + public var debugDescription: String { + + func formattedValue(_ any: Any) -> String { + + switch any { + + case let any as CoreStoreDebugStringConvertible: + return any.coreStoreDumpString + + default: + return "\(any)" + } + } + var string = "(\(String(reflecting: type(of: self)))) " + string.append(formattedValue(self)) + return string + } + + + // MARK: CoreStoreDebugStringConvertible + + public var coreStoreDumpString: String { + + func formattedValue(_ any: Any) -> String { + + switch any { + + case let any as CoreStoreDebugStringConvertible: + return any.coreStoreDumpString + + default: + return "\(any)" + } + } + func createFormattedString(_ firstLine: String, _ lastLine: String, _ info: [(key: String, value: Any)]) -> String { + + var string = firstLine + for (key, value) in info { + + string.append("\n.\(key) = \(formattedValue(value));") + } + string = string.replacingOccurrences(of: "\n", with: "\n\(String(repeating: " ", count: 4))") + string.append("\n\(lastLine)") + return string + } + return createFormattedString( + "(", ")", + [ + ("configuration", self.configuration as Any), + ("storeOptions", self.storeOptions as Any), + ("cacheFileURL", self.cacheFileURL), + ("cloudStorageOptions", self.cloudStorageOptions) + ] + ) + } // MARK: Private diff --git a/Sources/ICloudStoreObserver.swift b/Sources/ICloudStoreObserver.swift index 573dcc7..a3a451b 100644 --- a/Sources/ICloudStoreObserver.swift +++ b/Sources/ICloudStoreObserver.swift @@ -47,7 +47,7 @@ public protocol ICloudStoreObserver: class { - parameter dataStack: the `DataStack` that manages the peristent store */ func iCloudStoreWillFinishUbiquitousStoreInitialImport(storage: ICloudStore, dataStack: DataStack) - + /** Notifies that the initial ubiquitous store import completed @@ -105,24 +105,4 @@ public protocol ICloudStoreObserver: class { func iCloudStoreDidRemoveContent(storage: ICloudStore, dataStack: DataStack) } -@available(*, deprecated, message: "Please see the release notes and Core Data documentation.") -public extension ICloudStoreObserver { - - public func iCloudStoreWillFinishUbiquitousStoreInitialImport(storage: ICloudStore, dataStack: DataStack) {} - - public func iCloudStoreDidFinishUbiquitousStoreInitialImport(storage: ICloudStore, dataStack: DataStack) {} - - public func iCloudStoreWillAddAccount(storage: ICloudStore, dataStack: DataStack) {} - - public func iCloudStoreDidAddAccount(storage: ICloudStore, dataStack: DataStack) {} - - public func iCloudStoreWillRemoveAccount(storage: ICloudStore, dataStack: DataStack) {} - - public func iCloudStoreDidRemoveAccount(storage: ICloudStore, dataStack: DataStack) {} - - public func iCloudStoreWillRemoveContent(storage: ICloudStore, dataStack: DataStack) {} - - public func iCloudStoreDidRemoveContent(storage: ICloudStore, dataStack: DataStack) {} -} - #endif diff --git a/Sources/NSManagedObjectContext+Setup.swift b/Sources/NSManagedObjectContext+Setup.swift index 751ddb3..cf51460 100644 --- a/Sources/NSManagedObjectContext+Setup.swift +++ b/Sources/NSManagedObjectContext+Setup.swift @@ -72,7 +72,7 @@ internal extension NSManagedObjectContext { #if os(iOS) || os(macOS) context.observerForDidImportUbiquitousContentChangesNotification = NotificationObserver( - notificationName: NSNotification.Name.NSPersistentStoreDidImportUbiquitousContentChanges, + notificationName: NSNotification.Name("com.apple.coredata.ubiquity.importer.didfinishimport"), // NSNotification.Name.NSPersistentStoreDidImportUbiquitousContentChanges (used string literals to silence deprecation warning) object: coordinator, closure: { [weak context] (note) -> Void in