deleted obsoleted and deprecated API

This commit is contained in:
John Estropia
2019-03-30 23:56:39 +09:00
parent 0e254867b6
commit bf8a1062e0
34 changed files with 0 additions and 1972 deletions

View File

@@ -212,67 +212,4 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
group.wait()
self.context.reset()
}
// MARK: Deprecated
@available(*, deprecated, message: "Use the new auto-commiting methods `DataStack.perform(asynchronous:completion:)` or `DataStack.perform(asynchronous:success:failure:)`. Please read the documentation on the behavior of the new methods.")
public func commit(_ completion: @escaping (_ result: SaveResult) -> Void = { _ in }) {
CoreStore.assert(
self.transactionQueue.cs_isCurrentExecutionContext(),
"Attempted to commit a \(cs_typeName(self)) outside its designated queue."
)
CoreStore.assert(
!self.isCommitted,
"Attempted to commit a \(cs_typeName(self)) more than once."
)
self.autoCommit { (hasChanges, error) in
if let error = error {
completion(SaveResult(error))
}
else {
completion(SaveResult(hasChanges: hasChanges))
}
}
}
@available(*, deprecated, message: "Secondary tasks spawned from AsynchronousDataTransactions and SynchronousDataTransactions are no longer supported. ")
@discardableResult
public func beginSynchronous(_ closure: @escaping (_ transaction: SynchronousDataTransaction) -> Void) -> SaveResult? {
CoreStore.assert(
self.transactionQueue.cs_isCurrentExecutionContext(),
"Attempted to begin a child transaction from a \(cs_typeName(self)) outside its designated queue."
)
CoreStore.assert(
!self.isCommitted,
"Attempted to begin a child transaction from an already committed \(cs_typeName(self))."
)
let childTransaction = SynchronousDataTransaction(
mainContext: self.context,
queue: self.childTransactionQueue
)
childTransaction.transactionQueue.cs_sync {
closure(childTransaction)
if !childTransaction.isCommitted && childTransaction.hasChanges {
CoreStore.log(
.warning,
message: "The closure for the \(cs_typeName(childTransaction)) completed without being committed. All changes made within the transaction were discarded."
)
}
}
switch childTransaction.result {
case .none: return nil
case .some(let hasChanges, nil): return SaveResult(hasChanges: hasChanges)
case .some(_, let error?): return SaveResult(error)
}
}
}

View File

@@ -561,13 +561,4 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
return self.context
}
// MARK: Obsoleted
@available(swift, obsoleted: 3.1, renamed: "unsafeContext()")
public func internalContext() -> NSManagedObjectContext {
fatalError()
}
}

View File

@@ -442,49 +442,4 @@ public /*abstract*/ class BaseDataTransaction {
self.context.reset()
}
// MARK: Deprecated
@available(*, deprecated, message: "Use insertedObjects(_:) and pass the specific entity type")
public func insertedObjects() -> Set<NSManagedObject> {
CoreStore.assert(
self.transactionQueue.cs_isCurrentExecutionContext(),
"Attempted to access inserted objects from a \(cs_typeName(self)) outside its designated queue."
)
CoreStore.assert(
!self.isCommitted,
"Attempted to access inserted objects from an already committed \(cs_typeName(self))."
)
return self.context.insertedObjects
}
@available(*, deprecated, message: "Use updatedObjects(_:) and pass the specific entity type")
public func updatedObjects() -> Set<NSManagedObject> {
CoreStore.assert(
self.transactionQueue.cs_isCurrentExecutionContext(),
"Attempted to access updated objects from a \(cs_typeName(self)) outside its designated queue."
)
CoreStore.assert(
!self.isCommitted,
"Attempted to access updated objects from an already committed \(cs_typeName(self))."
)
return self.context.updatedObjects
}
@available(*, deprecated, message: "Use deletedObjects(_:) and pass the specific entity type")
public func deletedObjects() -> Set<NSManagedObject> {
CoreStore.assert(
self.transactionQueue.cs_isCurrentExecutionContext(),
"Attempted to access deleted objects from a \(cs_typeName(self)) outside its designated queue."
)
CoreStore.assert(
!self.isCommitted,
"Attempted to access deleted objects from an already committed \(cs_typeName(self))."
)
return self.context.deletedObjects
}
}

View File

@@ -156,41 +156,6 @@ public final class CSAsynchronousDataTransaction: CSBaseDataTransaction, CoreSto
super.init(swiftValue)
}
// MARK: Deprecated
@available(*, deprecated, message: "Use the new -[CSAsynchronousDataTransaction commitWithSuccess:failure:] method.")
@objc
public func commitWithCompletion(_ completion: ((_ result: CSSaveResult) -> Void)?) {
CoreStore.assert(
self.bridgeToSwift.transactionQueue.cs_isCurrentExecutionContext(),
"Attempted to commit a \(cs_typeName(self)) outside its designated queue."
)
CoreStore.assert(
!self.bridgeToSwift.isCommitted,
"Attempted to commit a \(cs_typeName(self)) more than once."
)
self.bridgeToSwift.commit { (result) in
completion?(result.bridgeToObjectiveC)
}
}
@available(*, deprecated, message: "Secondary tasks spawned from CSAsynchronousDataTransactions and CSSynchronousDataTransactions are no longer supported. ")
@objc
@discardableResult
public func beginSynchronous(_ closure: @escaping (_ transaction: CSSynchronousDataTransaction) -> Void) -> CSSaveResult? {
return bridge {
self.bridgeToSwift.beginSynchronous { (transaction) in
closure(transaction.bridgeToObjectiveC)
}
}
}
}

View File

@@ -251,28 +251,4 @@ public class CSBaseDataTransaction: NSObject {
self.swiftTransaction = swiftValue
super.init()
}
// MARK: Deprecated
@available(*, deprecated, message: "Use -[insertedObjectsOfType:] and pass the specific entity class")
@objc
public func insertedObjects() -> Set<NSManagedObject> {
return self.swiftTransaction.insertedObjects()
}
@available(*, deprecated, message: "Use -[updatedObjectsOfType:] and pass the specific entity class")
@objc
public func updatedObjects() -> Set<NSManagedObject> {
return self.swiftTransaction.updatedObjects()
}
@available(*, deprecated, message: "Use -[deletedObjectsOfType:] and pass the specific entity class")
@objc
public func deletedObjects() -> Set<NSManagedObject> {
return self.swiftTransaction.deletedObjects()
}
}

View File

@@ -125,21 +125,4 @@ extension CSCoreStore {
return self.defaultStack.addSQLiteStorageAndWait(storage, error: error)
}
// MARK: Deprecated
@available(*, deprecated, message: "Use the new +entityTypesByNameForType: method passing `[NSManagedObject class]` as argument.")
@objc
public static var entityClassesByName: [EntityName: NSManagedObject.Type] {
return CoreStore.entityTypesByName
}
@available(*, deprecated, message: "Use the new +entityTypesByNameForType: method passing `[NSManagedObject class]` as argument.")
@objc
public static func entityClassWithName(_ name: EntityName) -> NSManagedObject.Type? {
return CoreStore.entityTypesByName[name]
}
}

View File

@@ -91,15 +91,4 @@ extension CSCoreStore {
CoreStore.refreshAndMergeAllObjects()
}
// MARK: Deprecated
@available(*, deprecated, message: "Use the new +[CSCoreStore beginSynchronous:error:] API that reports failure using an error instance.")
@objc
@discardableResult
public static func beginSynchronous(_ closure: @escaping (_ transaction: CSSynchronousDataTransaction) -> Void) -> CSSaveResult? {
return self.defaultStack.beginSynchronous(closure)
}
}

View File

@@ -131,21 +131,4 @@ extension CSDataStack {
self.bridgeToSwift.refreshAndMergeAllObjects()
}
// MARK: Deprecated
@available(*, deprecated, message: "Use the new -[CSDataStack beginSynchronous:error:] API that reports failure using an error instance.")
@objc
@discardableResult
public func beginSynchronous(_ closure: @escaping (_ transaction: CSSynchronousDataTransaction) -> Void) -> CSSaveResult? {
return bridge {
self.bridgeToSwift.beginSynchronous { (transaction) in
closure(transaction.bridgeToObjectiveC)
}
}
}
}

View File

@@ -204,60 +204,6 @@ public final class CSDataStack: NSObject, CoreStoreObjectiveCType {
self.bridgeToSwift = swiftValue
super.init()
}
// MARK: Deprecated
@available(*, deprecated, message: "Use the -[initWithXcodeModelName:bundle:versionChain:] initializer.")
@objc
public convenience init(modelName: XcodeDataModelFileName?, bundle: Bundle?, versionChain: [String]?) {
self.init(
DataStack(
xcodeModelName: modelName ?? DataStack.applicationName,
bundle: bundle ?? Bundle.main,
migrationChain: versionChain.flatMap { MigrationChain($0) } ?? nil
)
)
}
@available(*, deprecated, message: "Use the -[initWithModelName:bundle:versionChain:] initializer.")
@objc
public convenience init(model: NSManagedObjectModel, versionChain: [String]?) {
self.init(
DataStack(
model: model,
migrationChain: versionChain.flatMap { MigrationChain($0) } ?? nil
)
)
}
@available(*, deprecated, message: "Use the -[initWithModelName:bundle:versionTree:] initializer.")
@objc
public convenience init(model: NSManagedObjectModel, versionTree: [String]?) {
self.init(
DataStack(
model: model,
migrationChain: versionTree.flatMap { MigrationChain($0) } ?? nil
)
)
}
@available(*, deprecated, message: "Use the new -entityTypesByNameForType: method passing `[NSManagedObject class]` as argument.")
@objc
public var entityClassesByName: [EntityName: NSManagedObject.Type] {
return self.bridgeToSwift.entityTypesByName
}
@available(*, deprecated, message: "Use the new -entityTypesByNameForType: method passing `[NSManagedObject class]` as argument.")
@objc
public func entityClassWithName(_ name: EntityName) -> NSManagedObject.Type? {
return self.bridgeToSwift.entityTypesByName[name]
}
}

View File

@@ -191,23 +191,6 @@ public final class CSSQLiteStore: NSObject, CSLocalStorage, CoreStoreObjectiveCT
self.bridgeToSwift = swiftValue
super.init()
}
// MARK: Obsoleted
@available(swift, obsoleted: 3.1, message: "The `mappingModelBundles` argument of this method is ignored. Use the new -[CSSQLiteStore initWithFileURL:configuration:localStorageOptions:]) initializer instead.")
@objc
public convenience init(fileURL: URL, configuration: ModelConfiguration, mappingModelBundles: [Bundle]?, localStorageOptions: Int) {
fatalError()
}
@available(swift, obsoleted: 3.1, message: "The `mappingModelBundles` argument of this method is ignored. Use the new -[CSSQLiteStore initWithFileName:configuration:localStorageOptions:]) initializer instead.")
@objc
public convenience init(fileName: String, configuration: ModelConfiguration, mappingModelBundles: [Bundle]?, localStorageOptions: Int) {
fatalError()
}
}

View File

@@ -1,147 +0,0 @@
//
// CSSaveResult.swift
// CoreStore
//
// Copyright © 2018 John Rommel Estropia
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
import Foundation
import CoreData
// MARK: - CSSaveResult
@available(*, deprecated, message: "Use APIs that report failures with `CSError`s instead.")
@objc
public final class CSSaveResult: NSObject, CoreStoreObjectiveCType {
@objc
public var isSuccess: Bool {
return self.bridgeToSwift.boolValue
}
@objc
public var isFailure: Bool {
return !self.bridgeToSwift.boolValue
}
@objc
public var hasChanges: Bool {
guard case .success(let hasChanges) = self.bridgeToSwift else {
return false
}
return hasChanges
}
@objc
public var error: NSError? {
guard case .failure(let error) = self.bridgeToSwift else {
return nil
}
return error.bridgeToObjectiveC
}
@objc
public func handleSuccess(_ success: (_ hasChanges: Bool) -> Void, failure: (_ error: NSError) -> Void) {
switch self.bridgeToSwift {
case .success(let hasChanges):
success(hasChanges)
case .failure(let error):
failure(error.bridgeToObjectiveC)
}
}
@objc
public func handleSuccess(_ success: (_ hasChanges: Bool) -> Void) {
guard case .success(let hasChanges) = self.bridgeToSwift else {
return
}
success(hasChanges)
}
@objc
public func handleFailure(_ failure: (_ error: NSError) -> Void) {
guard case .failure(let error) = self.bridgeToSwift else {
return
}
failure(error.bridgeToObjectiveC)
}
// MARK: NSObject
public override var hash: Int {
return self.bridgeToSwift.hashValue
}
public override func isEqual(_ object: Any?) -> Bool {
guard let object = object as? CSSaveResult else {
return false
}
return self.bridgeToSwift == object.bridgeToSwift
}
public override var description: String {
return "(\(String(reflecting: type(of: self)))) \(self.bridgeToSwift.coreStoreDumpString)"
}
// MARK: CoreStoreObjectiveCType
public let bridgeToSwift: SaveResult
public required init(_ swiftValue: SaveResult) {
self.bridgeToSwift = swiftValue
super.init()
}
}
// MARK: - SaveResult
@available(*, deprecated, message: "Use the new DataStack.perform(asynchronous:...) and DataStack.perform(synchronous:...) family of APIs")
extension SaveResult: CoreStoreSwiftType {
// MARK: CoreStoreSwiftType
public var bridgeToObjectiveC: CSSaveResult {
return CSSaveResult(self)
}
}

View File

@@ -143,33 +143,6 @@ public final class CSSynchronousDataTransaction: CSBaseDataTransaction, CoreStor
super.init(swiftValue)
}
// MARK: Deprecated
@available(*, deprecated, message: "Use the new -[CSSynchronousDataTransaction commitAndWaitWithError:] method")
@objc
public func commitAndWait() -> CSSaveResult {
return bridge {
self.bridgeToSwift.commitAndWait()
}
}
@available(*, deprecated, message: "Secondary tasks spawned from CSAsynchronousDataTransactions and CSSynchronousDataTransactions are no longer supported. ")
@objc
@discardableResult
public func beginSynchronous(_ closure: @escaping (_ transaction: CSSynchronousDataTransaction) -> Void) -> CSSaveResult? {
return bridge {
self.bridgeToSwift.beginSynchronous { (transaction) in
closure(transaction.bridgeToObjectiveC)
}
}
}
}

View File

@@ -203,51 +203,6 @@ public final class CSUnsafeDataTransaction: CSBaseDataTransaction, CoreStoreObje
super.init(swiftValue)
}
// MARK: Deprecated
@available(*, deprecated, renamed: "unsafeContext()")
@objc
public var internalContext: NSManagedObjectContext {
return self.bridgeToSwift.context
}
@available(*, deprecated, message: "Use the new -[CSUnsafeDataTransaction commitWithSuccess:failure:] method")
@objc
public func commit(_ completion: ((_ result: CSSaveResult) -> Void)?) {
self.bridgeToSwift.context.saveAsynchronouslyWithCompletion { (hasChanges, error) in
defer {
withExtendedLifetime(self, {})
}
if let error = error {
completion?(SaveResult(error).bridgeToObjectiveC)
}
else {
completion?(SaveResult(hasChanges: hasChanges).bridgeToObjectiveC)
}
}
}
@available(*, deprecated, message: "Use the new -[CSUnsafeDataTransaction commitAndWaitWithError:] method")
@objc
public func commitAndWait() -> CSSaveResult {
return bridge { () -> SaveResult in
switch self.bridgeToSwift.context.saveSynchronously(waitForMerge: true) {
case (let hasChanges, nil): return SaveResult(hasChanges: hasChanges)
case (_, let error?): return SaveResult(error)
}
}
}
}

View File

@@ -139,22 +139,4 @@ extension CoreStore {
return try self.defaultStack.addStorageAndWait(storage)
}
// MARK: Deprecated
@available(*, deprecated, message: "Use the new CoreStore.entityTypesByName(for:) method passing `NSManagedObject.self` as argument.")
public static var entityTypesByName: [EntityName: NSManagedObject.Type] {
return self.defaultStack.entityTypesByName
}
// MARK: Obsolete
@available(swift, obsoleted: 3.1, renamed: "entityDescription(for:)")
public static func entityDescriptionForType(_ type: NSManagedObject.Type) -> NSEntityDescription? {
return self.entityDescription(for: type)
}
}

View File

@@ -84,20 +84,4 @@ extension CoreStore {
self.defaultStack.refreshAndMergeAllObjects()
}
// MARK: Deprecated
@available(*, deprecated, message: "Use the new auto-commiting methods `perform(asynchronous:completion:)` or `perform(asynchronous:success:failure:)`. Please read the documentation on the behavior of the new methods.")
public static func beginAsynchronous(_ closure: @escaping (_ transaction: AsynchronousDataTransaction) -> Void) {
self.defaultStack.beginAsynchronous(closure)
}
@available(*, deprecated, message: "Use the new auto-commiting method `perform(synchronous:)`. Please read the documentation on the behavior of the new methods.")
@discardableResult
public static func beginSynchronous(_ closure: @escaping (_ transaction: SynchronousDataTransaction) -> Void) -> SaveResult? {
return self.defaultStack.beginSynchronous(closure)
}
}

View File

@@ -258,69 +258,3 @@ extension RelationshipContainer.ToOne {
return Where(relationship.keyPath, isMemberOf: sequence)
}
}
// MARK: Deprecated
extension DynamicObject where Self: CoreStoreObject {
@available(*, deprecated, message: "Use the String(keyPath:) initializer and pass the KeyPath: String(keyPath: \\Person.name)")
public static func keyPath<O, V>(_ attribute: (Self) -> ValueContainer<O>.Required<V>) -> String {
return attribute(self.meta).keyPath
}
@available(*, deprecated, message: "Use the String(keyPath:) initializer and pass the KeyPath: String(keyPath: \\Person.name)")
public static func keyPath<O, V>(_ attribute: (Self) -> ValueContainer<O>.Optional<V>) -> String {
return attribute(self.meta).keyPath
}
@available(*, deprecated, message: "Use the String(keyPath:) initializer and pass the KeyPath: String(keyPath: \\Person.friend)")
public static func keyPath<O, D>(_ relationship: (Self) -> RelationshipContainer<O>.ToOne<D>) -> String {
return relationship(self.meta).keyPath
}
@available(*, deprecated, message: "Use the String(keyPath:) initializer and pass the KeyPath: String(keyPath: \\Person.friends)")
public static func keyPath<O, D>(_ relationship: (Self) -> RelationshipContainer<O>.ToManyOrdered<D>) -> String {
return relationship(self.meta).keyPath
}
@available(*, deprecated, message: "Use the String(keyPath:) initializer and pass the KeyPath: String(keyPath: \\Person.friends)")
public static func keyPath<O, D>(_ relationship: (Self) -> RelationshipContainer<O>.ToManyUnordered<D>) -> String {
return relationship(self.meta).keyPath
}
@available(*, deprecated, message: "Use the Where<DynamicObject>(_:) initializer that accepts the same closure argument")
public static func `where`(_ condition: (Self) -> Where<Self>) -> Where<Self> {
return condition(self.meta)
}
@available(*, deprecated, message: "Use the new OrderBy<DynamicObject>(ascending:) overload that accepts the same closure argument")
public static func orderBy<O, V>(ascending attribute: (Self) -> ValueContainer<O>.Required<V>) -> OrderBy<Self> {
return OrderBy(.ascending(attribute(self.meta).keyPath))
}
@available(*, deprecated, message: "Use the new OrderBy<DynamicObject>(ascending:) overload that accepts the same closure argument")
public static func orderBy<O, V>(ascending attribute: (Self) -> ValueContainer<O>.Optional<V>) -> OrderBy<Self> {
return OrderBy(.ascending(attribute(self.meta).keyPath))
}
@available(*, deprecated, message: "Use the new OrderBy<DynamicObject>(descending:) overload that accepts the same closure argument")
public static func orderBy<O, V>(descending attribute: (Self) -> ValueContainer<O>.Required<V>) -> OrderBy<Self> {
return OrderBy(.descending(attribute(self.meta).keyPath))
}
@available(*, deprecated, message: "Use the new OrderBy<DynamicObject>(descending:) overload that accepts the same closure argument")
public static func orderBy<O, V>(descending attribute: (Self) -> ValueContainer<O>.Optional<V>) -> OrderBy<Self> {
return OrderBy(.descending(attribute(self.meta).keyPath))
}
}

View File

@@ -507,13 +507,4 @@ extension DataStack: FetchableSource, QueryableSource {
return self.mainContext
}
// MARK: Obsoleted
@available(swift, obsoleted: 3.1, renamed: "unsafeContext()")
public func internalContext() -> NSManagedObjectContext {
fatalError()
}
}

View File

@@ -164,56 +164,4 @@ extension DataStack {
)
self.mainContext.refreshAndMergeAllObjects()
}
// MARK: Deprecated
@available(*, deprecated, message: "Use the new auto-commiting methods `perform(asynchronous:completion:)` or `perform(asynchronous:success:failure:)`. Please read the documentation on the behavior of the new methods.")
public func beginAsynchronous(_ closure: @escaping (_ transaction: AsynchronousDataTransaction) -> Void) {
let transaction = AsynchronousDataTransaction(
mainContext: self.rootSavingContext,
queue: self.childTransactionQueue
)
transaction.transactionQueue.cs_async {
closure(transaction)
if !transaction.isCommitted && transaction.hasChanges {
CoreStore.log(
.warning,
message: "The closure for the \(cs_typeName(transaction)) completed without being committed. All changes made within the transaction were discarded."
)
}
}
}
@available(*, deprecated, message: "Use the new auto-commiting method `perform(synchronous:)`. Please read the documentation on the behavior of the new methods.")
@discardableResult
public func beginSynchronous(_ closure: @escaping (_ transaction: SynchronousDataTransaction) -> Void) -> SaveResult? {
let transaction = SynchronousDataTransaction(
mainContext: self.rootSavingContext,
queue: self.childTransactionQueue
)
transaction.transactionQueue.cs_sync {
closure(transaction)
if !transaction.isCommitted && transaction.hasChanges {
CoreStore.log(
.warning,
message: "The closure for the \(cs_typeName(transaction)) completed without being committed. All changes made within the transaction were discarded."
)
}
}
switch transaction.result {
case .none: return nil
case .some(let hasChanges, nil): return SaveResult(hasChanges: hasChanges)
case .some(_, let error?): return SaveResult(error)
}
}
}

View File

@@ -614,57 +614,4 @@ public final class DataStack: Equatable {
}
}
}
// MARK: Deprecated
@available(*, deprecated, renamed: "init(xcodeModelName:bundle:migrationChain:)")
public convenience init(modelName: XcodeDataModelFileName, bundle: Bundle = Bundle.main, migrationChain: MigrationChain = nil) {
self.init(
xcodeModelName: modelName,
bundle: bundle,
migrationChain: migrationChain
)
}
@available(*, deprecated, message: "Use the new DataStack.init(schemaHistory:) initializer passing an UnsafeDataModelSchema instance as argument")
public convenience init(model: NSManagedObjectModel, migrationChain: MigrationChain = nil) {
let modelVersion = migrationChain.leafVersions.first!
self.init(
schemaHistory: SchemaHistory(
allSchema: [
UnsafeDataModelSchema(
modelName: modelVersion,
model: model
)
],
migrationChain: migrationChain,
exactCurrentModelVersion: modelVersion
)
)
}
@available(*, deprecated, message: "Use the new DataStack.entityTypesByName(for:) method passing `NSManagedObject.self` as argument.")
public var entityTypesByName: [EntityName: NSManagedObject.Type] {
return self.entityTypesByName(for: NSManagedObject.self)
}
// MARK: Obsolete
@available(swift, obsoleted: 3.1, renamed: "entityDescription(for:)")
public func entityDescriptionForType(_ type: NSManagedObject.Type) -> NSEntityDescription? {
return self.entityDescription(for: type)
}
@available(swift, obsoleted: 3.1, renamed: "objectID(forURIRepresentation:)")
public func objectIDForURIRepresentation(_ url: URL) -> NSManagedObjectID? {
return self.objectID(forURIRepresentation: url)
}
}

View File

@@ -1,569 +0,0 @@
//
// ICloudStore.swift
// CoreStore
//
// Copyright © 2018 John Rommel Estropia
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
import Foundation
import CoreData
#if os(iOS) || os(macOS)
// MARK: - ICloudStore
/**
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, 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
```
guard let storage = ICloudStore(
ubiquitousContentName: "MyAppCloudData",
ubiquitousContentTransactionLogsSubdirectory: "logs/config1",
ubiquitousContainerID: "iCloud.com.mycompany.myapp.containername",
ubiquitousPeerToken: "9614d658014f4151a95d8048fb717cf0",
configuration: "Config1",
cloudStorageOptions: .recreateLocalStoreOnModelMismatch
) else {
// iCloud is not available on the device
return
}
CoreStore.addStorage(
storage,
completion: { result in
// ...
}
)
```
- parameter ubiquitousContentName: the name of the store in iCloud. This is required and should not be empty, and should not contain periods (`.`).
- parameter ubiquitousContentTransactionLogsSubdirectory: a required relative path for the transaction logs
- parameter ubiquitousContainerID: a container if your app has multiple ubiquity container identifiers in its entitlements
- parameter ubiquitousPeerToken: a per-application salt to allow multiple apps on the same device to share a Core Data store integrated with iCloud
- parameter configuration: an optional configuration name from the model file. If not specified, defaults to `nil`, the "Default" configuration. Note that if you have multiple configurations, you will need to specify a different `ubiquitousContentName` explicitly for each of them.
- parameter cloudStorageOptions: When the `ICloudStore` is passed to the `DataStack`'s `addStorage()` methods, tells the `DataStack` how to setup the persistent store. Defaults to `.None`.
*/
public required init?(ubiquitousContentName: String, ubiquitousContentTransactionLogsSubdirectory: String, ubiquitousContainerID: String? = nil, ubiquitousPeerToken: String? = nil, configuration: ModelConfiguration = nil, cloudStorageOptions: CloudStorageOptions = nil) {
CoreStore.assert(
!ubiquitousContentName.isEmpty,
"The ubiquitousContentName cannot be empty."
)
CoreStore.assert(
!ubiquitousContentName.contains("."),
"The ubiquitousContentName cannot contain periods."
)
CoreStore.assert(
!ubiquitousContentTransactionLogsSubdirectory.isEmpty,
"The ubiquitousContentURLRelativePath should not be empty."
)
CoreStore.assert(
ubiquitousPeerToken?.isEmpty != true,
"The ubiquitousPeerToken should not be empty if provided."
)
let fileManager = FileManager.default
guard let cacheFolderURL = fileManager.url(forUbiquityContainerIdentifier: ubiquitousContainerID) else {
return nil
}
let cacheFileURL = cacheFolderURL.appendingPathComponent(ubiquitousContentTransactionLogsSubdirectory)
var storeOptions: [String: Any] = [
NSSQLitePragmasOption: ["journal_mode": "WAL"],
NSPersistentStoreUbiquitousContentNameKey: ubiquitousContentName
]
storeOptions[NSPersistentStoreUbiquitousContentURLKey] = ubiquitousContentTransactionLogsSubdirectory
storeOptions[NSPersistentStoreUbiquitousContainerIdentifierKey] = ubiquitousContainerID
storeOptions[NSPersistentStoreUbiquitousPeerTokenOption] = ubiquitousPeerToken
self.cacheFileURL = cacheFileURL
self.configuration = configuration
self.cloudStorageOptions = cloudStorageOptions
self.storeOptions = storeOptions
}
/**
Registers an `ICloudStoreObserver` to start receive notifications from the ubiquitous store
- parameter observer: the observer to start sending ubiquitous notifications to
*/
public func addObserver<T: ICloudStoreObserver>(_ observer: T) {
CoreStore.assert(
Thread.isMainThread,
"Attempted to add an observer of type \(cs_typeName(observer)) outside the main thread."
)
self.removeObserver(observer)
self.registerNotification(
&self.willFinishInitialImportKey,
name: Notification.Name.iCloudUbiquitousStoreWillFinishInitialImport,
toObserver: observer,
callback: { (observer, storage, dataStack) in
observer.iCloudStoreWillFinishUbiquitousStoreInitialImport(storage: storage, dataStack: dataStack)
}
)
self.registerNotification(
&self.didFinishInitialImportKey,
name: Notification.Name.iCloudUbiquitousStoreDidFinishInitialImport,
toObserver: observer,
callback: { (observer, storage, dataStack) in
observer.iCloudStoreDidFinishUbiquitousStoreInitialImport(storage: storage, dataStack: dataStack)
}
)
self.registerNotification(
&self.willAddAccountKey,
name: Notification.Name.iCloudUbiquitousStoreWillAddAccount,
toObserver: observer,
callback: { (observer, storage, dataStack) in
observer.iCloudStoreWillAddAccount(storage: storage, dataStack: dataStack)
}
)
self.registerNotification(
&self.didAddAccountKey,
name: Notification.Name.iCloudUbiquitousStoreDidAddAccount,
toObserver: observer,
callback: { (observer, storage, dataStack) in
observer.iCloudStoreDidAddAccount(storage: storage, dataStack: dataStack)
}
)
self.registerNotification(
&self.willRemoveAccountKey,
name: Notification.Name.iCloudUbiquitousStoreWillRemoveAccount,
toObserver: observer,
callback: { (observer, storage, dataStack) in
observer.iCloudStoreWillRemoveAccount(storage: storage, dataStack: dataStack)
}
)
self.registerNotification(
&self.didRemoveAccountKey,
name: Notification.Name.iCloudUbiquitousStoreDidRemoveAccount,
toObserver: observer,
callback: { (observer, storage, dataStack) in
observer.iCloudStoreDidRemoveAccount(storage: storage, dataStack: dataStack)
}
)
self.registerNotification(
&self.willRemoveContentKey,
name: Notification.Name.iCloudUbiquitousStoreWillRemoveContent,
toObserver: observer,
callback: { (observer, storage, dataStack) in
observer.iCloudStoreWillRemoveContent(storage: storage, dataStack: dataStack)
}
)
self.registerNotification(
&self.didRemoveContentKey,
name: Notification.Name.iCloudUbiquitousStoreDidRemoveContent,
toObserver: observer,
callback: { (observer, storage, dataStack) in
observer.iCloudStoreDidRemoveContent(storage: storage, dataStack: dataStack)
}
)
}
/**
Unregisters an `ICloudStoreObserver` to stop receiving notifications from the ubiquitous store
- parameter observer: the observer to stop sending ubiquitous notifications to
*/
public func removeObserver(_ observer: ICloudStoreObserver) {
CoreStore.assert(
Thread.isMainThread,
"Attempted to remove an observer of type \(cs_typeName(observer)) outside the main thread."
)
let nilValue: AnyObject? = nil
cs_setAssociatedRetainedObject(
nilValue,
forKey: &self.willFinishInitialImportKey,
inObject: observer
)
cs_setAssociatedRetainedObject(
nilValue,
forKey: &self.didFinishInitialImportKey,
inObject: observer
)
cs_setAssociatedRetainedObject(
nilValue,
forKey: &self.willAddAccountKey,
inObject: observer
)
cs_setAssociatedRetainedObject(
nilValue,
forKey: &self.didAddAccountKey,
inObject: observer
)
cs_setAssociatedRetainedObject(
nilValue,
forKey: &self.willRemoveAccountKey,
inObject: observer
)
cs_setAssociatedRetainedObject(
nilValue,
forKey: &self.didRemoveAccountKey,
inObject: observer
)
cs_setAssociatedRetainedObject(
nilValue,
forKey: &self.willRemoveContentKey,
inObject: observer
)
cs_setAssociatedRetainedObject(
nilValue,
forKey: &self.didRemoveContentKey,
inObject: observer
)
}
// MARK: StorageInterface
/**
The string identifier for the `NSPersistentStore`'s `type` property. For `SQLiteStore`s, this is always set to `NSSQLiteStoreType`.
*/
public static let storeType = NSSQLiteStoreType
/**
The configuration name in the model file
*/
public let configuration: ModelConfiguration
/**
The options dictionary for the `NSPersistentStore`. For `SQLiteStore`s, this is always set to
```
[NSSQLitePragmasOption: ["journal_mode": "WAL"]]
```
*/
public let storeOptions: [AnyHashable: Any]?
/**
Do not call directly. Used by the `DataStack` internally.
*/
public func cs_didAddToDataStack(_ dataStack: DataStack) {
self.cs_didRemoveFromDataStack(dataStack)
self.dataStack = dataStack
let coordinator = dataStack.coordinator
cs_setAssociatedRetainedObject(
NotificationObserver(
notificationName: Notification.Name.NSPersistentStoreCoordinatorStoresWillChange,
object: coordinator,
closure: { [weak self, weak dataStack] (note) -> Void in
guard let `self` = self,
let dataStack = dataStack,
let userInfo = note.userInfo,
let transitionType = userInfo[NSPersistentStoreUbiquitousTransitionTypeKey] as? NSNumber else {
return
}
let notification: Notification.Name
switch NSPersistentStoreUbiquitousTransitionType(rawValue: transitionType.uintValue) {
case .initialImportCompleted?:
notification = Notification.Name.iCloudUbiquitousStoreWillFinishInitialImport
case .accountAdded?:
notification = Notification.Name.iCloudUbiquitousStoreWillAddAccount
case .accountRemoved?:
notification = Notification.Name.iCloudUbiquitousStoreWillRemoveAccount
case .contentRemoved?:
notification = Notification.Name.iCloudUbiquitousStoreWillRemoveContent
default:
return
}
NotificationCenter.default.post(
name: notification,
object: self,
userInfo: [String(describing: DataStack.self): dataStack]
)
}
),
forKey: &Static.persistentStoreCoordinatorWillChangeStores,
inObject: self
)
cs_setAssociatedRetainedObject(
NotificationObserver(
notificationName: NSNotification.Name.NSPersistentStoreCoordinatorStoresDidChange,
object: coordinator,
closure: { [weak self, weak dataStack] (note) -> Void in
guard let `self` = self,
let dataStack = dataStack,
let userInfo = note.userInfo,
let transitionType = userInfo[NSPersistentStoreUbiquitousTransitionTypeKey] as? NSNumber else {
return
}
let notification: Notification.Name
switch NSPersistentStoreUbiquitousTransitionType(rawValue: transitionType.uintValue) {
case .initialImportCompleted?:
notification = Notification.Name.iCloudUbiquitousStoreDidFinishInitialImport
case .accountAdded?:
notification = Notification.Name.iCloudUbiquitousStoreDidAddAccount
case .accountRemoved?:
notification = Notification.Name.iCloudUbiquitousStoreDidRemoveAccount
case .contentRemoved?:
notification = Notification.Name.iCloudUbiquitousStoreDidRemoveContent
default:
return
}
NotificationCenter.default.post(
name: notification,
object: self,
userInfo: [String(describing: DataStack.self): dataStack]
)
}
),
forKey: &Static.persistentStoreCoordinatorDidChangeStores,
inObject: self
)
}
/**
Do not call directly. Used by the `DataStack` internally.
*/
public func cs_didRemoveFromDataStack(_ dataStack: DataStack) {
let coordinator = dataStack.coordinator
let nilValue: AnyObject? = nil
cs_setAssociatedRetainedObject(
nilValue,
forKey: &Static.persistentStoreCoordinatorWillChangeStores,
inObject: coordinator
)
cs_setAssociatedRetainedObject(
nilValue,
forKey: &Static.persistentStoreCoordinatorDidChangeStores,
inObject: coordinator
)
self.dataStack = nil
}
// MARK: CloudStorage
/**
The `NSURL` that points to the ubiquity container file
*/
public let cacheFileURL: URL
/**
Options that tell the `DataStack` how to setup the persistent store
*/
public var cloudStorageOptions: CloudStorageOptions
/**
The options dictionary for the specified `CloudStorageOptions`
*/
public func dictionary(forOptions options: CloudStorageOptions) -> [AnyHashable: Any]? {
if options == .none {
return self.storeOptions
}
var storeOptions = self.storeOptions ?? [:]
if options.contains(.allowSynchronousLightweightMigration) {
storeOptions[NSMigratePersistentStoresAutomaticallyOption] = true
storeOptions[NSInferMappingModelAutomaticallyOption] = true
}
if options.contains(.recreateLocalStoreOnModelMismatch) {
storeOptions[NSPersistentStoreRebuildFromUbiquitousContentOption] = true
}
return storeOptions
}
/**
Called by the `DataStack` to perform actual deletion of the store file from disk. Do not call directly! The `sourceModel` argument is a hint for the existing store's model version. For `SQLiteStore`, this converts the database's WAL journaling mode to DELETE before deleting the file.
*/
public func cs_eraseStorageAndWait(soureModel: NSManagedObjectModel) throws {
let cacheFileURL = self.cacheFileURL
try autoreleasepool {
let journalUpdatingCoordinator = NSPersistentStoreCoordinator(managedObjectModel: soureModel)
let options = [
NSSQLitePragmasOption: ["journal_mode": "DELETE"],
NSPersistentStoreRemoveUbiquitousMetadataOption: true
] as [String : Any]
let store = try journalUpdatingCoordinator.addPersistentStore(
ofType: type(of: self).storeType,
configurationName: self.configuration,
at: cacheFileURL,
options: options
)
try journalUpdatingCoordinator.remove(store)
try NSPersistentStoreCoordinator.removeUbiquitousContentAndPersistentStore(
at: cacheFileURL,
options: options
)
}
}
// 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
fileprivate struct Static {
fileprivate static var persistentStoreCoordinatorWillChangeStores: Void?
fileprivate static var persistentStoreCoordinatorDidChangeStores: Void?
}
private var willFinishInitialImportKey: Void?
private var didFinishInitialImportKey: Void?
private var willAddAccountKey: Void?
private var didAddAccountKey: Void?
private var willRemoveAccountKey: Void?
private var didRemoveAccountKey: Void?
private var willRemoveContentKey: Void?
private var didRemoveContentKey: Void?
private weak var dataStack: DataStack?
private func registerNotification<T: ICloudStoreObserver>(_ notificationKey: UnsafeRawPointer, name: Notification.Name, toObserver observer: T, callback: @escaping (_ observer: T, _ storage: ICloudStore, _ dataStack: DataStack) -> Void) {
cs_setAssociatedRetainedObject(
NotificationObserver(
notificationName: name,
object: self,
closure: { [weak self, weak observer] (note) -> Void in
guard let `self` = self,
let observer = observer,
let dataStack = note.userInfo?[String(describing: DataStack.self)] as? DataStack,
self.dataStack === dataStack else {
return
}
callback(observer, self, dataStack)
}
),
forKey: notificationKey,
inObject: observer
)
}
}
// MARK: - Notification Keys
extension Notification.Name {
fileprivate static let iCloudUbiquitousStoreWillFinishInitialImport = Notification.Name(rawValue: "iCloudUbiquitousStoreWillFinishInitialImport")
fileprivate static let iCloudUbiquitousStoreDidFinishInitialImport = Notification.Name(rawValue: "iCloudUbiquitousStoreDidFinishInitialImport")
fileprivate static let iCloudUbiquitousStoreWillAddAccount = Notification.Name(rawValue: "iCloudUbiquitousStoreWillAddAccount")
fileprivate static let iCloudUbiquitousStoreDidAddAccount = Notification.Name(rawValue: "iCloudUbiquitousStoreDidAddAccount")
fileprivate static let iCloudUbiquitousStoreWillRemoveAccount = Notification.Name(rawValue: "iCloudUbiquitousStoreWillRemoveAccount")
fileprivate static let iCloudUbiquitousStoreDidRemoveAccount = Notification.Name(rawValue: "iCloudUbiquitousStoreDidRemoveAccount")
fileprivate static let iCloudUbiquitousStoreWillRemoveContent = Notification.Name(rawValue: "iCloudUbiquitousStoreWillRemoveContent")
fileprivate static let iCloudUbiquitousStoreDidRemoveContent = Notification.Name(rawValue: "iCloudUbiquitousStoreDidRemoveContent")
}
#endif

View File

@@ -1,108 +0,0 @@
//
// ICloudStoreObserver.swift
// CoreStore
//
// Copyright © 2018 John Rommel Estropia
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
import Foundation
#if os(iOS) || os(macOS)
// MARK: - ICloudStoreObserver
/**
Implement the `ICloudStoreObserver` protocol to observe ubiquitous storage notifications from the specified iCloud store.
Note that `ICloudStoreObserver` methods are only called when all the following conditions are true:
- the observer is registered to the `ICloudStore` via the `ICloudStore.addObserver(_:)` method
- the `ICloudStore` was added to a `DataStack`
- the `ICloudStore` and the `DataStack` are still persisted in memory
*/
@available(*, deprecated, message: "Please see the release notes and Core Data documentation.")
public protocol ICloudStoreObserver: class {
/**
Notifies that the initial ubiquitous store import will complete
- parameter storage: the `ICloudStore` instance being observed
- parameter dataStack: the `DataStack` that manages the peristent store
*/
func iCloudStoreWillFinishUbiquitousStoreInitialImport(storage: ICloudStore, dataStack: DataStack)
/**
Notifies that the initial ubiquitous store import completed
- parameter storage: the `ICloudStore` instance being observed
- parameter dataStack: the `DataStack` that manages the peristent store
*/
func iCloudStoreDidFinishUbiquitousStoreInitialImport(storage: ICloudStore, dataStack: DataStack)
/**
Notifies that an iCloud account will be added to the coordinator
- parameter storage: the `ICloudStore` instance being observed
- parameter dataStack: the `DataStack` that manages the peristent store
*/
func iCloudStoreWillAddAccount(storage: ICloudStore, dataStack: DataStack)
/**
Notifies that an iCloud account was added to the coordinator
- parameter storage: the `ICloudStore` instance being observed
- parameter dataStack: the `DataStack` that manages the peristent store
*/
func iCloudStoreDidAddAccount(storage: ICloudStore, dataStack: DataStack)
/**
Notifies that an iCloud account will be removed from the coordinator
- parameter storage: the `ICloudStore` instance being observed
- parameter dataStack: the `DataStack` that manages the peristent store
*/
func iCloudStoreWillRemoveAccount(storage: ICloudStore, dataStack: DataStack)
/**
Notifies that an iCloud account was removed from the coordinator
- parameter storage: the `ICloudStore` instance being observed
- parameter dataStack: the `DataStack` that manages the peristent store
*/
func iCloudStoreDidRemoveAccount(storage: ICloudStore, dataStack: DataStack)
/**
Notifies that iCloud contents will be deleted
- parameter storage: the `ICloudStore` instance being observed
- parameter dataStack: the `DataStack` that manages the peristent store
*/
func iCloudStoreWillRemoveContent(storage: ICloudStore, dataStack: DataStack)
/**
Notifies that iCloud contents were deleted
- parameter storage: the `ICloudStore` instance being observed
- parameter dataStack: the `DataStack` that manages the peristent store
*/
func iCloudStoreDidRemoveContent(storage: ICloudStore, dataStack: DataStack)
}
#endif

View File

@@ -86,19 +86,4 @@ extension ImportableObject {
return true
}
// MARK: Obsolete
@available(swift, obsoleted: 3.0.0, renamed: "shouldInsert(from:in:)")
public static func shouldInsertFromImportSource(_ source: ImportSource, inTransaction transaction: BaseDataTransaction) -> Bool {
return Self.shouldInsert(from: source, in: transaction)
}
@available(swift, obsoleted: 3.0.0, renamed: "didInsert(from:in:)")
public func didInsertFromImportSource(_ source: ImportSource, inTransaction transaction: BaseDataTransaction) throws {
try self.didInsert(from: source, in: transaction)
}
}

View File

@@ -160,37 +160,4 @@ extension ImportableUniqueObject {
try self.update(from: source, in: transaction)
}
// MARK: Obsolete
@available(swift, obsoleted: 3.1, renamed: "shouldInsert(from:in:)")
public static func shouldInsertFromImportSource(_ source: ImportSource, inTransaction transaction: BaseDataTransaction) -> Bool {
return Self.shouldInsert(from: source, in: transaction)
}
@available(swift, obsoleted: 3.1, renamed: "shouldUpdate(from:in:)")
public static func shouldUpdateFromImportSource(_ source: ImportSource, inTransaction transaction: BaseDataTransaction) -> Bool {
return Self.shouldUpdate(from: source, in: transaction)
}
@available(swift, obsoleted: 3.1, renamed: "uniqueID(from:in:)")
public static func uniqueIDFromImportSource(_ source: ImportSource, inTransaction transaction: BaseDataTransaction) throws -> UniqueIDType? {
return try Self.uniqueID(from: source, in: transaction)
}
@available(swift, obsoleted: 3.1, renamed: "didInsert(from:in:)")
public func didInsertFromImportSource(_ source: ImportSource, inTransaction transaction: BaseDataTransaction) throws {
try self.didInsert(from: source, in: transaction)
}
@available(swift, obsoleted: 3.1, renamed: "update(from:in:)")
public func updateFromImportSource(_ source: ImportSource, inTransaction transaction: BaseDataTransaction) throws {
try self.update(from: source, in: transaction)
}
}

View File

@@ -1,103 +0,0 @@
//
// LegacySQLiteStore.swift
// CoreStore
//
// Copyright © 2018 John Rommel Estropia
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
import Foundation
import CoreData
// MARK: - LegacySQLiteStore
/**
A storage interface backed by an SQLite database that was created before CoreStore 2.0.0.
*/
@available(swift, obsoleted: 3.1, message: "`LegacySQLiteStore` previous users should now use `SQLiteStore`'s new SQLiteStore.legacy(fileName:configuration:migrationMappingProviders:localStorageOptions:) or SQLiteStore.legacy() methods to create an `SQLiteStore` with legacy paths.")
public final class LegacySQLiteStore: LocalStorage {
@available(swift, obsoleted: 3.1, message: "Use `SQLiteStore`'s new SQLiteStore.init(fileURL:configuration:migrationMappingProviders:localStorageOptions:) initializer.")
public init(fileURL: URL, configuration: ModelConfiguration = nil, mappingModelBundles: [Bundle] = Bundle.allBundles, localStorageOptions: LocalStorageOptions = nil) {
fatalError()
}
@available(swift, obsoleted: 3.1, message: "Use `SQLiteStore`'s new SQLiteStore.legacy(fileName:configuration:migrationMappingProviders:localStorageOptions:) factory method.")
public init(fileName: String, configuration: ModelConfiguration = nil, mappingModelBundles: [Bundle] = Bundle.allBundles, localStorageOptions: LocalStorageOptions = nil) {
fatalError()
}
@available(swift, obsoleted: 3.1, message: "Use `SQLiteStore`'s new SQLiteStore.legacy(...) factory method.")
public init() {
fatalError()
}
// MARK: StorageInterface
public static let storeType = NSSQLiteStoreType
public func dictionary(forOptions options: LocalStorageOptions) -> [AnyHashable: Any]? {
fatalError()
}
public let configuration: ModelConfiguration
public let storeOptions: [AnyHashable: Any]? = [NSSQLitePragmasOption: ["journal_mode": "WAL"]]
public func cs_didAddToDataStack(_ dataStack: DataStack) {
fatalError()
}
public func cs_didRemoveFromDataStack(_ dataStack: DataStack) {
fatalError()
}
// MAKR: LocalStorage
public let fileURL: URL
public let migrationMappingProviders: [SchemaMappingProvider]
public var localStorageOptions: LocalStorageOptions
public func cs_finalizeStorageAndWait(soureModelHint: NSManagedObjectModel) throws {
fatalError()
}
public func cs_eraseStorageAndWait(metadata: [String: Any], soureModelHint: NSManagedObjectModel?) throws {
fatalError()
}
// MARK: Private
private weak var dataStack: DataStack?
}

View File

@@ -25,44 +25,6 @@
import Foundation
import CoreData
// MARK: - CSDataStack
@available(macOS 10.12, *)
extension CSDataStack {
@available(*, deprecated, message: "CoreStore will obsolete NSFetchedResultsController support in the future in favor of CSListMonitor")
@objc
public func createFetchedResultsControllerFrom(_ from: CSFrom, sectionBy: CSSectionBy, fetchClauses: [CSFetchClause]) -> NSFetchedResultsController<NSManagedObject> {
return createFRC(
fromContext: self.bridgeToSwift.mainContext,
from: from,
sectionBy: sectionBy,
fetchClauses: fetchClauses
)
}
}
// MARK: - CSUnsafeDataTransaction
@available(macOS 10.12, *)
extension CSUnsafeDataTransaction {
@available(*, deprecated, message: "CoreStore will obsolete NSFetchedResultsController support in the future in favor of CSListMonitor")
@objc
public func createFetchedResultsControllerFrom(_ from: CSFrom, sectionBy: CSSectionBy, fetchClauses: [CSFetchClause]) -> NSFetchedResultsController<NSManagedObject> {
return createFRC(
fromContext: self.bridgeToSwift.context,
from: from,
sectionBy: sectionBy,
fetchClauses: fetchClauses
)
}
}
// MARK: - Private

View File

@@ -206,58 +206,4 @@ extension NSManagedObject {
self.managedObjectContext?.refresh(self, mergeChanges: true)
}
// MARK: Deprecated
@available(*, deprecated, renamed: "getValue(forKvcKey:)")
@nonobjc
public func accessValueForKVCKey(_ KVCKey: KeyPathString) -> Any? {
self.willAccessValue(forKey: KVCKey)
defer {
self.didAccessValue(forKey: KVCKey)
}
return self.primitiveValue(forKey: KVCKey)
}
@available(*, deprecated, renamed: "getValue(forKvcKey:didGetValue:)")
@discardableResult
@nonobjc
public func accessValueForKVCKey<T>(_ KVCKey: KeyPathString, _ didAccessPrimitiveValue: (Any?) throws -> T) rethrows -> T {
self.willAccessValue(forKey: KVCKey)
defer {
self.didAccessValue(forKey: KVCKey)
}
return try didAccessPrimitiveValue(self.primitiveValue(forKey: KVCKey))
}
@available(*, deprecated, renamed: "setValue(_:forKvcKey:)")
@nonobjc
public func setValue(_ value: Any?, forKVCKey KVCKey: KeyPathString) {
self.willChangeValue(forKey: KVCKey)
defer {
self.didChangeValue(forKey: KVCKey)
}
self.setPrimitiveValue(value, forKey: KVCKey)
}
@available(*, deprecated, renamed: "setValue(_:forKvcKey:didSetValue:)")
@discardableResult
@nonobjc
public func setValue<T>(_ value: Any?, forKVCKey KVCKey: KeyPathString, _ didSetPrimitiveValue: (Any?) throws -> T) rethrows -> T {
self.willChangeValue(forKey: KVCKey)
defer {
self.didChangeValue(forKey: KVCKey)
}
self.setPrimitiveValue(value, forKey: KVCKey)
return try didSetPrimitiveValue(value)
}
}

View File

@@ -333,15 +333,6 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
return try self.deleteAll(fetchRequest)
}
// MARK: Deprecated
@available(*, deprecated, renamed: "unsafeContext()")
public func internalContext() -> NSManagedObjectContext {
return self.unsafeContext()
}
}

View File

@@ -352,19 +352,4 @@ public final class SQLiteStore: LocalStorage {
// MARK: Private
private weak var dataStack: DataStack?
// MARK: Obsoleted
@available(swift, obsoleted: 3.1, message: "The `mappingModelBundles` argument of this method is ignored. Use the new SQLiteStore.init(fileURL:configuration:migrationMappingProviders:localStorageOptions:) initializer instead.")
public convenience init(fileURL: URL, configuration: ModelConfiguration = nil, mappingModelBundles: [Bundle], localStorageOptions: LocalStorageOptions = nil) {
fatalError()
}
@available(swift, obsoleted: 3.1, message: "The `mappingModelBundles` argument of this method is ignored. Use the new SQLiteStore.init(fileName:configuration:migrationMappingProviders:localStorageOptions:) initializer instead.")
public convenience init(fileName: String, configuration: ModelConfiguration = nil, mappingModelBundles: [Bundle], localStorageOptions: LocalStorageOptions = nil) {
fatalError()
}
}

View File

@@ -1,58 +0,0 @@
//
// SaveResult.swift
// CoreStore
//
// Copyright © 2018 John Rommel Estropia
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
import Foundation
// MARK: - SaveResult
@available(*, deprecated, message: "Use the new DataStack.perform(asynchronous:...) and DataStack.perform(synchronous:...) family of APIs")
public enum SaveResult: Hashable {
case success(hasChanges: Bool)
case failure(CoreStoreError)
public var boolValue: Bool {
switch self {
case .success: return true
case .failure: return false
}
}
// MARK: Internal
internal init(hasChanges: Bool) {
self = .success(hasChanges: hasChanges)
}
internal init(_ error: CoreStoreError) {
self = .failure(error)
}
}

View File

@@ -164,79 +164,4 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
}
return result
}
// MARK: Deprecated
@available(*, deprecated, message: "Use the new auto-commit method DataStack.perform(synchronous:waitForAllObservers:)")
public func commitAndWait() -> SaveResult {
CoreStore.assert(
self.transactionQueue.cs_isCurrentExecutionContext(),
"Attempted to commit a \(cs_typeName(self)) outside its designated queue."
)
CoreStore.assert(
!self.isCommitted,
"Attempted to commit a \(cs_typeName(self)) more than once."
)
switch self.autoCommit(waitForMerge: true) {
case (let hasChanges, nil): return SaveResult(hasChanges: hasChanges)
case (_, let error?): return SaveResult(error)
}
}
@available(*, deprecated, message: "Use the new auto-commit method DataStack.perform(synchronous:waitForAllObservers:)")
public func commit() -> SaveResult {
CoreStore.assert(
self.transactionQueue.cs_isCurrentExecutionContext(),
"Attempted to commit a \(cs_typeName(self)) outside its designated queue."
)
CoreStore.assert(
!self.isCommitted,
"Attempted to commit a \(cs_typeName(self)) more than once."
)
switch self.autoCommit(waitForMerge: false) {
case (let hasChanges, nil): return SaveResult(hasChanges: hasChanges)
case (_, let error?): return SaveResult(error)
}
}
@available(*, deprecated, message: "Secondary tasks spawned from AsynchronousDataTransactions and SynchronousDataTransactions are no longer supported. ")
@discardableResult
public func beginSynchronous(_ closure: @escaping (_ transaction: SynchronousDataTransaction) -> Void) -> SaveResult? {
CoreStore.assert(
self.transactionQueue.cs_isCurrentExecutionContext(),
"Attempted to begin a child transaction from a \(cs_typeName(self)) outside its designated queue."
)
CoreStore.assert(
!self.isCommitted,
"Attempted to begin a child transaction from an already committed \(cs_typeName(self))."
)
let childTransaction = SynchronousDataTransaction(
mainContext: self.context,
queue: self.childTransactionQueue
)
childTransaction.transactionQueue.cs_sync {
closure(childTransaction)
if !childTransaction.isCommitted && childTransaction.hasChanges {
CoreStore.log(
.warning,
message: "The closure for the \(cs_typeName(childTransaction)) completed without being committed. All changes made within the transaction were discarded."
)
}
}
switch childTransaction.result {
case .none: return nil
case .some(let hasChanges, nil): return SaveResult(hasChanges: hasChanges)
case .some(_, let error?): return SaveResult(error)
}
}
}

View File

@@ -254,25 +254,6 @@ public enum TransformableContainer<O: CoreStoreObject> {
private let customGetter: ((_ partialObject: PartialObject<O>) -> V)?
private let customSetter: ((_ partialObject: PartialObject<O>, _ newValue: V) -> Void)?
// MARK: Deprecated
@available(*, unavailable, message: "Indexes are now set through the Entity<T> initializer, which now supports compound indexes.")
public convenience init(
_ keyPath: KeyPathString,
initial: @autoclosure @escaping () -> V,
isIndexed: Bool,
isTransient: Bool = false,
allowsExternalBinaryDataStorage: Bool = false,
versionHashModifier: @autoclosure @escaping () -> String? = nil,
renamingIdentifier: @autoclosure @escaping () -> String? = nil,
customGetter: ((_ partialObject: PartialObject<O>) -> V)? = nil,
customSetter: ((_ partialObject: PartialObject<O>, _ newValue: V) -> Void)? = nil,
affectedByKeyPaths: @autoclosure @escaping () -> Set<String> = []) {
fatalError()
}
}
@@ -467,25 +448,6 @@ public enum TransformableContainer<O: CoreStoreObject> {
private let customGetter: ((_ partialObject: PartialObject<O>) -> V?)?
private let customSetter: ((_ partialObject: PartialObject<O>, _ newValue: V?) -> Void)?
// MARK: Deprecated
@available(*, unavailable, message: "Indexes are now set through the Entity<T> initializer, which now supports compound indexes.")
public convenience init(
_ keyPath: KeyPathString,
initial: @autoclosure @escaping () -> V? = nil,
isIndexed: Bool,
isTransient: Bool = false,
allowsExternalBinaryDataStorage: Bool = false,
versionHashModifier: @autoclosure @escaping () -> String? = nil,
renamingIdentifier: @autoclosure @escaping () -> String? = nil,
customGetter: ((_ partialObject: PartialObject<O>) -> V?)? = nil,
customSetter: ((_ partialObject: PartialObject<O>, _ newValue: V?) -> Void)? = nil,
affectedByKeyPaths: @autoclosure @escaping () -> Set<String> = []) {
fatalError()
}
}
}

View File

@@ -249,24 +249,6 @@ public enum ValueContainer<O: CoreStoreObject> {
private let customGetter: ((_ partialObject: PartialObject<O>) -> V)?
private let customSetter: ((_ partialObject: PartialObject<O>, _ newValue: V) -> Void)?
// MARK: Deprecated
@available(*, unavailable, message: "Indexes are now set through the Entity<T> initializer, which now supports compound indexes.")
public convenience init(
_ keyPath: KeyPathString,
initial: @autoclosure @escaping () -> V,
isIndexed: Bool,
isTransient: Bool = false,
versionHashModifier: @autoclosure @escaping () -> String? = nil,
renamingIdentifier: @autoclosure @escaping () -> String? = nil,
customGetter: ((_ partialObject: PartialObject<O>) -> V)? = nil,
customSetter: ((_ partialObject: PartialObject<O>, _ newValue: V) -> Void)? = nil,
affectedByKeyPaths: @autoclosure @escaping () -> Set<String> = []) {
fatalError()
}
}
@@ -461,24 +443,6 @@ public enum ValueContainer<O: CoreStoreObject> {
private let customGetter: ((_ partialObject: PartialObject<O>) -> V?)?
private let customSetter: ((_ partialObject: PartialObject<O>, _ newValue: V?) -> Void)?
// MARK: Deprecated
@available(*, unavailable, message: "Indexes are now set through the Entity<T> initializer, which now supports compound indexes.")
public convenience init(
_ keyPath: KeyPathString,
initial: @autoclosure @escaping () -> V? = nil,
isIndexed: Bool,
isTransient: Bool = false,
versionHashModifier: @autoclosure @escaping () -> String? = nil,
renamingIdentifier: @autoclosure @escaping () -> String? = nil,
customGetter: ((_ partialObject: PartialObject<O>) -> V?)? = nil,
customSetter: ((_ partialObject: PartialObject<O>, _ newValue: V?) -> Void)? = nil,
affectedByKeyPaths: @autoclosure @escaping () -> Set<String> = []) {
fatalError()
}
}
}

View File

@@ -545,49 +545,3 @@ extension Sequence where Iterator.Element: WhereClauseType {
return Where(NSCompoundPredicate(type: .or, subpredicates: self.map({ $0.predicate })))
}
}
// MARK: - Deprecated
extension Where {
@available(*, deprecated, renamed: "&&?")
public static func && (left: Where<D>, right: Where<D>?) -> Where<D> {
if let right = right {
return left && right
}
return left
}
@available(*, deprecated, renamed: "&&?")
public static func && (left: Where<D>?, right: Where<D>) -> Where<D> {
if let left = left {
return left && right
}
return right
}
@available(*, deprecated, renamed: "||?")
public static func || (left: Where<D>, right: Where<D>?) -> Where<D> {
if let right = right {
return left || right
}
return left
}
@available(*, deprecated, renamed: "||?")
public static func || (left: Where<D>?, right: Where<D>) -> Where<D> {
if let left = left {
return left || right
}
return right
}
}