mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-24 02:11:26 +01:00
WIP
This commit is contained in:
@@ -101,7 +101,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
!self.isCommitted,
|
||||
"Attempted to create an entity of type \(cs_typeName(T)) from an already committed \(cs_typeName(self))."
|
||||
"Attempted to create an entity of type \(cs_typeName(T.self)) from an already committed \(cs_typeName(self))."
|
||||
)
|
||||
|
||||
return super.create(into)
|
||||
@@ -113,7 +113,6 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
|
||||
- parameter object: the `NSManagedObject` type to be edited
|
||||
- returns: an editable proxy for the specified `NSManagedObject`.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public override func edit<T: NSManagedObject>(_ object: T?) -> T? {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -131,12 +130,11 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
|
||||
- parameter objectID: the `NSManagedObjectID` for the object to be edited
|
||||
- returns: an editable proxy for the specified `NSManagedObject`.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public override func edit<T: NSManagedObject>(_ into: Into<T>, _ objectID: NSManagedObjectID) -> T? {
|
||||
|
||||
CoreStore.assert(
|
||||
!self.isCommitted,
|
||||
"Attempted to update an entity of type \(cs_typeName(T)) from an already committed \(cs_typeName(self))."
|
||||
"Attempted to update an entity of type \(cs_typeName(T.self)) from an already committed \(cs_typeName(self))."
|
||||
)
|
||||
|
||||
return super.edit(into, objectID)
|
||||
|
||||
@@ -57,7 +57,7 @@ public /*abstract*/ class BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
self.isRunningInAllowedQueue(),
|
||||
"Attempted to create an entity of type \(cs_typeName(T)) outside its designated queue."
|
||||
"Attempted to create an entity of type \(cs_typeName(T.self)) outside its designated queue."
|
||||
)
|
||||
|
||||
let context = self.context
|
||||
@@ -118,7 +118,6 @@ public /*abstract*/ class BaseDataTransaction {
|
||||
- parameter object: the `NSManagedObject` type to be edited
|
||||
- returns: an editable proxy for the specified `NSManagedObject`.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func edit<T: NSManagedObject>(_ object: T?) -> T? {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -139,17 +138,16 @@ public /*abstract*/ class BaseDataTransaction {
|
||||
- parameter objectID: the `NSManagedObjectID` for the object to be edited
|
||||
- returns: an editable proxy for the specified `NSManagedObject`.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func edit<T: NSManagedObject>(_ into: Into<T>, _ objectID: NSManagedObjectID) -> T? {
|
||||
|
||||
CoreStore.assert(
|
||||
self.isRunningInAllowedQueue(),
|
||||
"Attempted to update an entity of type \(cs_typeName(T)) outside its designated queue."
|
||||
"Attempted to update an entity of type \(cs_typeName(T.self)) outside its designated queue."
|
||||
)
|
||||
CoreStore.assert(
|
||||
into.inferStoreIfPossible
|
||||
|| (into.configuration ?? Into.defaultConfigurationName) == objectID.persistentStore?.configurationName,
|
||||
"Attempted to update an entity of type \(cs_typeName(T)) but the specified persistent store do not match the `NSManagedObjectID`."
|
||||
"Attempted to update an entity of type \(cs_typeName(T.self)) but the specified persistent store do not match the `NSManagedObjectID`."
|
||||
)
|
||||
return self.fetchExisting(objectID) as? T
|
||||
}
|
||||
@@ -221,7 +219,6 @@ public /*abstract*/ class BaseDataTransaction {
|
||||
|
||||
- returns: a `Set` of pending `NSManagedObject`s that were inserted to the transaction.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func insertedObjects() -> Set<NSManagedObject> {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -242,7 +239,6 @@ public /*abstract*/ class BaseDataTransaction {
|
||||
- parameter entity: the `NSManagedObject` subclass to filter
|
||||
- returns: a `Set` of pending `NSManagedObject`s of the specified type that were inserted to the transaction.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func insertedObjects<T: NSManagedObject>(_ entity: T.Type) -> Set<T> {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -262,7 +258,6 @@ public /*abstract*/ class BaseDataTransaction {
|
||||
|
||||
- returns: a `Set` of pending `NSManagedObjectID`s that were inserted to the transaction.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func insertedObjectIDs() -> Set<NSManagedObjectID> {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -283,7 +278,6 @@ public /*abstract*/ class BaseDataTransaction {
|
||||
- parameter entity: the `NSManagedObject` subclass to filter
|
||||
- returns: a `Set` of pending `NSManagedObjectID`s of the specified type that were inserted to the transaction.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func insertedObjectIDs<T: NSManagedObject>(_ entity: T.Type) -> Set<NSManagedObjectID> {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -303,7 +297,6 @@ public /*abstract*/ class BaseDataTransaction {
|
||||
|
||||
- returns: a `Set` of pending `NSManagedObject`s that were updated to the transaction.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func updatedObjects() -> Set<NSManagedObject> {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -324,7 +317,6 @@ public /*abstract*/ class BaseDataTransaction {
|
||||
- parameter entity: the `NSManagedObject` subclass to filter
|
||||
- returns: a `Set` of pending `NSManagedObject`s of the specified type that were updated in the transaction.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func updatedObjects<T: NSManagedObject>(_ entity: T.Type) -> Set<T> {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -344,7 +336,6 @@ public /*abstract*/ class BaseDataTransaction {
|
||||
|
||||
- returns: a `Set` of pending `NSManagedObjectID`s that were updated in the transaction.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func updatedObjectIDs() -> Set<NSManagedObjectID> {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -365,7 +356,6 @@ public /*abstract*/ class BaseDataTransaction {
|
||||
- parameter entity: the `NSManagedObject` subclass to filter
|
||||
- returns: a `Set` of pending `NSManagedObjectID`s of the specified type that were updated in the transaction.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func updatedObjectIDs<T: NSManagedObject>(_ entity: T.Type) -> Set<NSManagedObjectID> {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -385,7 +375,6 @@ public /*abstract*/ class BaseDataTransaction {
|
||||
|
||||
- returns: a `Set` of pending `NSManagedObject`s that were deleted from the transaction.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func deletedObjects() -> Set<NSManagedObject> {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -406,7 +395,6 @@ public /*abstract*/ class BaseDataTransaction {
|
||||
- parameter entity: the `NSManagedObject` subclass to filter
|
||||
- returns: a `Set` of pending `NSManagedObject`s of the specified type that were deleted from the transaction.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func deletedObjects<T: NSManagedObject>(_ entity: T.Type) -> Set<T> {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -427,7 +415,6 @@ public /*abstract*/ class BaseDataTransaction {
|
||||
- parameter entity: the `NSManagedObject` subclass to filter
|
||||
- returns: a `Set` of pending `NSManagedObjectID`s of the specified type that were deleted from the transaction.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func deletedObjectIDs() -> Set<NSManagedObjectID> {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -448,7 +435,6 @@ public /*abstract*/ class BaseDataTransaction {
|
||||
- parameter entity: the `NSManagedObject` subclass to filter
|
||||
- returns: a `Set` of pending `NSManagedObjectID`s of the specified type that were deleted from the transaction.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func deletedObjectIDs<T: NSManagedObject>(_ entity: T.Type) -> Set<NSManagedObjectID> {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -468,7 +454,7 @@ public /*abstract*/ class BaseDataTransaction {
|
||||
|
||||
internal let context: NSManagedObjectContext
|
||||
internal let transactionQueue: GCDQueue
|
||||
internal let childTransactionQueue: GCDQueue = .createSerial("com.corestore.datastack.childtransactionqueue")
|
||||
internal let childTransactionQueue = GCDQueue.createSerial("com.corestore.datastack.childtransactionqueue")
|
||||
internal let supportsUndo: Bool
|
||||
internal let bypassesQueueing: Bool
|
||||
|
||||
|
||||
@@ -57,7 +57,6 @@ public extension CoreStore {
|
||||
- prameter supportsUndo: `undo()`, `redo()`, and `rollback()` methods are only available when this parameter is `true`, otherwise those method will raise an exception. Defaults to `false`. Note that turning on Undo support may heavily impact performance especially on iOS or watchOS where memory is limited.
|
||||
- returns: a `UnsafeDataTransaction` instance where creates, updates, and deletes can be made.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public static func beginUnsafe(supportsUndo: Bool = false) -> UnsafeDataTransaction {
|
||||
|
||||
return self.defaultStack.beginUnsafe(supportsUndo: supportsUndo)
|
||||
|
||||
@@ -67,7 +67,6 @@ public extension DataStack {
|
||||
- prameter supportsUndo: `undo()`, `redo()`, and `rollback()` methods are only available when this parameter is `true`, otherwise those method will raise an exception. Defaults to `false`. Note that turning on Undo support may heavily impact performance especially on iOS or watchOS where memory is limited.
|
||||
- returns: a `UnsafeDataTransaction` instance where creates, updates, and deletes can be made.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func beginUnsafe(supportsUndo: Bool = false) -> UnsafeDataTransaction {
|
||||
|
||||
return UnsafeDataTransaction(
|
||||
|
||||
@@ -32,7 +32,7 @@ import CoreData
|
||||
/**
|
||||
An `Into` clause contains the destination entity and destination persistent store for a `create(...)` method. A common usage is to just indicate the entity:
|
||||
```
|
||||
let person = transaction.create(Into(MyPersonEntity))
|
||||
let person = transaction.create(Into<MyPersonEntity>())
|
||||
```
|
||||
For cases where multiple `NSPersistentStore`s contain the same entity, the destination configuration's name needs to be specified as well:
|
||||
```
|
||||
@@ -66,7 +66,7 @@ public struct Into<T: NSManagedObject>: Hashable {
|
||||
/**
|
||||
Initializes an `Into` clause with the specified entity type.
|
||||
```
|
||||
let person = transaction.create(Into(MyPersonEntity))
|
||||
let person = transaction.create(Into(MyPersonEntity.self))
|
||||
```
|
||||
|
||||
- parameter entity: the `NSManagedObject` type to be created
|
||||
@@ -79,7 +79,7 @@ public struct Into<T: NSManagedObject>: Hashable {
|
||||
/**
|
||||
Initializes an `Into` clause with the specified entity class.
|
||||
```
|
||||
let person = transaction.create(Into(MyPersonEntity))
|
||||
let person = transaction.create(Into(MyPersonEntity.self))
|
||||
```
|
||||
|
||||
- parameter entityClass: the `NSManagedObject` class type to be created
|
||||
@@ -88,7 +88,7 @@ public struct Into<T: NSManagedObject>: Hashable {
|
||||
|
||||
CoreStore.assert(
|
||||
entityClass is T.Type,
|
||||
"Attempted to create generic type \(cs_typeName(Into<T>)) with entity class \(cs_typeName(entityClass))"
|
||||
"Attempted to create generic type \(cs_typeName(Into<T>.self)) with entity class \(cs_typeName(entityClass))"
|
||||
)
|
||||
self.init(entityClass: entityClass, configuration: nil, inferStoreIfPossible: true)
|
||||
}
|
||||
@@ -133,7 +133,7 @@ public struct Into<T: NSManagedObject>: Hashable {
|
||||
|
||||
CoreStore.assert(
|
||||
entityClass is T.Type,
|
||||
"Attempted to create generic type \(cs_typeName(Into<T>)) with entity class \(cs_typeName(entityClass))"
|
||||
"Attempted to create generic type \(cs_typeName(Into<T>.self)) with entity class \(cs_typeName(entityClass))"
|
||||
)
|
||||
self.init(entityClass: entityClass, configuration: configuration, inferStoreIfPossible: false)
|
||||
}
|
||||
@@ -181,7 +181,6 @@ public struct Into<T: NSManagedObject>: Hashable {
|
||||
|
||||
// MARK: - Into: Equatable
|
||||
|
||||
@warn_unused_result
|
||||
public func == <T: NSManagedObject, U: NSManagedObject>(lhs: Into<T>, rhs: Into<U>) -> Bool {
|
||||
|
||||
return lhs.entityClass == rhs.entityClass
|
||||
@@ -189,7 +188,6 @@ public func == <T: NSManagedObject, U: NSManagedObject>(lhs: Into<T>, rhs: Into<
|
||||
&& lhs.inferStoreIfPossible == rhs.inferStoreIfPossible
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func != <T: NSManagedObject, U: NSManagedObject>(lhs: Into<T>, rhs: Into<U>) -> Bool {
|
||||
|
||||
return lhs.entityClass == rhs.entityClass
|
||||
|
||||
@@ -49,9 +49,9 @@ import Foundation
|
||||
// ...
|
||||
let result = transaction.commit()
|
||||
switch result {
|
||||
case .Success(let hasChanges):
|
||||
case .success(let hasChanges):
|
||||
// hasChanges indicates if there were changes or not
|
||||
case .Failure(let error):
|
||||
case .failure(let error):
|
||||
// error is a CoreStoreError enum value
|
||||
}
|
||||
}
|
||||
@@ -60,12 +60,12 @@ import Foundation
|
||||
public enum SaveResult: Hashable {
|
||||
|
||||
/**
|
||||
`SaveResult.Success` indicates that the `commit()` for the transaction succeeded, either because the save succeeded or because there were no changes to save. The associated value `hasChanges` indicates if there were saved changes or not.
|
||||
`SaveResult.success` indicates that the `commit()` for the transaction succeeded, either because the save succeeded or because there were no changes to save. The associated value `hasChanges` indicates if there were saved changes or not.
|
||||
*/
|
||||
case success(hasChanges: Bool)
|
||||
|
||||
/**
|
||||
`SaveResult.Failure` indicates that the `commit()` for the transaction failed. The associated object for this value is a `CoreStoreError` enum value.
|
||||
`SaveResult.failure` indicates that the `commit()` for the transaction failed. The associated object for this value is a `CoreStoreError` enum value.
|
||||
*/
|
||||
case failure(CoreStoreError)
|
||||
|
||||
@@ -116,7 +116,6 @@ extension SaveResult: Boolean {
|
||||
|
||||
// MARK: - SaveResult: Equatable
|
||||
|
||||
@warn_unused_result
|
||||
public func == (lhs: SaveResult, rhs: SaveResult) -> Bool {
|
||||
|
||||
switch (lhs, rhs) {
|
||||
|
||||
@@ -96,7 +96,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
|
||||
|
||||
CoreStore.assert(
|
||||
!self.isCommitted,
|
||||
"Attempted to create an entity of type \(cs_typeName(T)) from an already committed \(cs_typeName(self))."
|
||||
"Attempted to create an entity of type \(cs_typeName(T.self)) from an already committed \(cs_typeName(self))."
|
||||
)
|
||||
|
||||
return super.create(into)
|
||||
@@ -108,7 +108,6 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
|
||||
- parameter object: the `NSManagedObject` type to be edited
|
||||
- returns: an editable proxy for the specified `NSManagedObject`.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public override func edit<T: NSManagedObject>(_ object: T?) -> T? {
|
||||
|
||||
CoreStore.assert(
|
||||
@@ -126,12 +125,11 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
|
||||
- parameter objectID: the `NSManagedObjectID` for the object to be edited
|
||||
- returns: an editable proxy for the specified `NSManagedObject`.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public override func edit<T: NSManagedObject>(_ into: Into<T>, _ objectID: NSManagedObjectID) -> T? {
|
||||
|
||||
CoreStore.assert(
|
||||
!self.isCommitted,
|
||||
"Attempted to update an entity of type \(cs_typeName(T)) from an already committed \(cs_typeName(self))."
|
||||
"Attempted to update an entity of type \(cs_typeName(T.self)) from an already committed \(cs_typeName(self))."
|
||||
)
|
||||
|
||||
return super.edit(into, objectID)
|
||||
|
||||
@@ -129,7 +129,6 @@ public final class UnsafeDataTransaction: BaseDataTransaction {
|
||||
- prameter supportsUndo: `undo()`, `redo()`, and `rollback()` methods are only available when this parameter is `true`, otherwise those method will raise an exception. Defaults to `false`. Note that turning on Undo support may heavily impact performance especially on iOS or watchOS where memory is limited.
|
||||
- returns: an `UnsafeDataTransaction` instance where creates, updates, and deletes can be made.
|
||||
*/
|
||||
@warn_unused_result
|
||||
public func beginUnsafe(supportsUndo: Bool = false) -> UnsafeDataTransaction {
|
||||
|
||||
return UnsafeDataTransaction(
|
||||
|
||||
Reference in New Issue
Block a user