mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-19 07:27:02 +01:00
WIP: CSImportableObject
This commit is contained in:
@@ -36,12 +36,12 @@ import CoreData
|
||||
public final class CSAsynchronousDataTransaction: CSBaseDataTransaction {
|
||||
|
||||
/**
|
||||
Saves the transaction changes. This method should not be used after the `commit()` method was already called once.
|
||||
Saves the transaction changes. This method should not be used after the `-commitWithCompletion:` method was already called once.
|
||||
|
||||
- parameter completion: the block executed after the save completes. Success or failure is reported by the `CSSaveResult` argument of the block.
|
||||
*/
|
||||
@objc
|
||||
public func commit(completion: ((result: CSSaveResult) -> Void)?) {
|
||||
public func commitWithCompletion(completion: ((result: CSSaveResult) -> Void)?) {
|
||||
|
||||
self.swift.commit { (result) in
|
||||
|
||||
@@ -49,133 +49,93 @@ public final class CSAsynchronousDataTransaction: CSBaseDataTransaction {
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// Begins a child transaction synchronously where NSManagedObject creates, updates, and deletes can be made. This method should not be used after the `commit()` method was already called once.
|
||||
//
|
||||
// - parameter closure: the block where creates, updates, and deletes can be made to the transaction. Transaction blocks are executed serially in a background queue, and all changes are made from a concurrent `NSManagedObjectContext`.
|
||||
// - returns: a `SaveResult` value indicating success or failure, or `nil` if the transaction was not comitted synchronously
|
||||
// */
|
||||
// public func beginSynchronous(closure: (transaction: SynchronousDataTransaction) -> Void) -> SaveResult? {
|
||||
//
|
||||
// CoreStore.assert(
|
||||
// self.transactionQueue.isCurrentExecutionContext(),
|
||||
// "Attempted to begin a child transaction from a \(typeName(self)) outside its designated queue."
|
||||
// )
|
||||
// CoreStore.assert(
|
||||
// !self.isCommitted,
|
||||
// "Attempted to begin a child transaction from an already committed \(typeName(self))."
|
||||
// )
|
||||
//
|
||||
// return SynchronousDataTransaction(
|
||||
// mainContext: self.context,
|
||||
// queue: self.childTransactionQueue,
|
||||
// closure: closure).performAndWait()
|
||||
// }
|
||||
//
|
||||
//
|
||||
// // MARK: BaseDataTransaction
|
||||
//
|
||||
// /**
|
||||
// Creates a new `NSManagedObject` with the specified entity type.
|
||||
//
|
||||
// - parameter into: the `Into` clause indicating the destination `NSManagedObject` entity type and the destination configuration
|
||||
// - returns: a new `NSManagedObject` instance of the specified entity type.
|
||||
// */
|
||||
// public override func create<T: NSManagedObject>(into: Into<T>) -> T {
|
||||
//
|
||||
// CoreStore.assert(
|
||||
// !self.isCommitted,
|
||||
// "Attempted to create an entity of type \(typeName(T)) from an already committed \(typeName(self))."
|
||||
// )
|
||||
//
|
||||
// return super.create(into)
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// Returns an editable proxy of a specified `NSManagedObject`. This method should not be used after the `commit()` method was already called once.
|
||||
//
|
||||
// - 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(
|
||||
// !self.isCommitted,
|
||||
// "Attempted to update an entity of type \(typeName(object)) from an already committed \(typeName(self))."
|
||||
// )
|
||||
//
|
||||
// return super.edit(object)
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// Returns an editable proxy of the object with the specified `NSManagedObjectID`. This method should not be used after the `commit()` method was already called once.
|
||||
//
|
||||
// - parameter into: an `Into` clause specifying the entity type
|
||||
// - 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 \(typeName(T)) from an already committed \(typeName(self))."
|
||||
// )
|
||||
//
|
||||
// return super.edit(into, objectID)
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// Deletes a specified `NSManagedObject`. This method should not be used after the `commit()` method was already called once.
|
||||
//
|
||||
// - parameter object: the `NSManagedObject` type to be deleted
|
||||
// */
|
||||
// public override func delete(object: NSManagedObject?) {
|
||||
//
|
||||
// CoreStore.assert(
|
||||
// !self.isCommitted,
|
||||
// "Attempted to delete an entity of type \(typeName(object)) from an already committed \(typeName(self))."
|
||||
// )
|
||||
//
|
||||
// super.delete(object)
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// Deletes the specified `NSManagedObject`s.
|
||||
//
|
||||
// - parameter object1: the `NSManagedObject` type to be deleted
|
||||
// - parameter object2: another `NSManagedObject` type to be deleted
|
||||
// - parameter objects: other `NSManagedObject`s type to be deleted
|
||||
// */
|
||||
// public override func delete(object1: NSManagedObject?, _ object2: NSManagedObject?, _ objects: NSManagedObject?...) {
|
||||
//
|
||||
// CoreStore.assert(
|
||||
// !self.isCommitted,
|
||||
// "Attempted to delete an entities from an already committed \(typeName(self))."
|
||||
// )
|
||||
//
|
||||
// super.delete(([object1, object2] + objects).flatMap { $0 })
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// Deletes the specified `NSManagedObject`s.
|
||||
//
|
||||
// - parameter objects: the `NSManagedObject`s type to be deleted
|
||||
// */
|
||||
// public override func delete<S: SequenceType where S.Generator.Element: NSManagedObject>(objects: S) {
|
||||
//
|
||||
// CoreStore.assert(
|
||||
// !self.isCommitted,
|
||||
// "Attempted to delete an entities from an already committed \(typeName(self))."
|
||||
// )
|
||||
//
|
||||
// super.delete(objects)
|
||||
// }
|
||||
/**
|
||||
Begins a child transaction synchronously where `NSManagedObject` creates, updates, and deletes can be made. This method should not be used after the `-commitWithCompletion:` method was already called once.
|
||||
|
||||
- parameter closure: the block where creates, updates, and deletes can be made to the transaction. Transaction blocks are executed serially in a background queue, and all changes are made from a concurrent `NSManagedObjectContext`.
|
||||
- returns: a `CSSaveResult` value indicating success or failure, or `nil` if the transaction was not comitted synchronously
|
||||
*/
|
||||
@objc
|
||||
public func beginSynchronous(closure: (transaction: CSSynchronousDataTransaction) -> Void) -> CSSaveResult? {
|
||||
|
||||
return bridge {
|
||||
|
||||
self.swift.beginSynchronous { (transaction) in
|
||||
|
||||
closure(transaction: transaction.objc)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: BaseDataTransaction
|
||||
|
||||
/**
|
||||
Creates a new `NSManagedObject` with the specified entity type.
|
||||
|
||||
- parameter into: the `CSInto` clause indicating the destination `NSManagedObject` entity type and the destination configuration
|
||||
- returns: a new `NSManagedObject` instance of the specified entity type.
|
||||
*/
|
||||
@objc
|
||||
public override func createInto(into: CSInto) -> NSManagedObject {
|
||||
|
||||
return self.swift.create(into.swift)
|
||||
}
|
||||
|
||||
/**
|
||||
Returns an editable proxy of a specified `NSManagedObject`. This method should not be used after the `-commitWithCompletion:` method was already called once.
|
||||
|
||||
- parameter object: the `NSManagedObject` type to be edited
|
||||
- returns: an editable proxy for the specified `NSManagedObject`.
|
||||
*/
|
||||
@objc
|
||||
@warn_unused_result
|
||||
public override func editObject(object: NSManagedObject?) -> NSManagedObject? {
|
||||
|
||||
return self.swift.edit(object)
|
||||
}
|
||||
|
||||
/**
|
||||
Returns an editable proxy of the object with the specified `NSManagedObjectID`. This method should not be used after the `-commitWithCompletion:` method was already called once.
|
||||
|
||||
- parameter into: a `CSInto` clause specifying the entity type
|
||||
- parameter objectID: the `NSManagedObjectID` for the object to be edited
|
||||
- returns: an editable proxy for the specified `NSManagedObject`.
|
||||
*/
|
||||
@objc
|
||||
@warn_unused_result
|
||||
public override func editInto(into: CSInto, objectID: NSManagedObjectID) -> NSManagedObject? {
|
||||
|
||||
return self.swift.edit(into.swift, objectID)
|
||||
}
|
||||
|
||||
/**
|
||||
Deletes a specified `NSManagedObject`. This method should not be used after the `-commitWithCompletion:` method was already called once.
|
||||
|
||||
- parameter object: the `NSManagedObject` type to be deleted
|
||||
*/
|
||||
@objc
|
||||
public override func deleteObject(object: NSManagedObject?) {
|
||||
|
||||
self.swift.delete(object)
|
||||
}
|
||||
|
||||
/**
|
||||
Deletes the specified `NSManagedObject`s.
|
||||
|
||||
- parameter objects: the `NSManagedObject`s type to be deleted
|
||||
*/
|
||||
@objc
|
||||
public override func deleteObjects(objects: [NSManagedObject]) {
|
||||
|
||||
self.swift.delete(objects)
|
||||
}
|
||||
|
||||
|
||||
// MARK: CoreStoreBridge
|
||||
|
||||
internal typealias SwiftType = AsynchronousDataTransaction
|
||||
|
||||
internal override var swift: AsynchronousDataTransaction {
|
||||
|
||||
return super.swift as! AsynchronousDataTransaction
|
||||
|
||||
Reference in New Issue
Block a user