Support typed errors. Misc formatting

This commit is contained in:
John Estropia
2024-09-10 11:14:39 +09:00
parent c9e091a6a4
commit 5dcf29011a
74 changed files with 3987 additions and 1441 deletions

View File

@@ -41,7 +41,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
```
- Important: Never use `try?` or `try!` on a `cancel()` call. Always use `try`. Using `try?` will swallow the cancellation and the transaction will proceed to commit as normal. Using `try!` will crash the app as `cancel()` will *always* throw an error.
*/
public func cancel() throws -> Never {
public func cancel() throws(CoreStoreError) -> Never {
throw CoreStoreError.userCancelled
}
@@ -66,8 +66,10 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
- parameter into: the `Into` clause indicating the destination `NSManagedObject` or `CoreStoreObject` entity type and the destination configuration
- returns: a new `NSManagedObject` or `CoreStoreObject` instance of the specified entity type.
*/
public override func create<O>(_ into: Into<O>) -> O {
public override func create<O>(
_ into: Into<O>
) -> O {
Internals.assert(
!self.isCommitted,
"Attempted to create an entity of type \(Internals.typeName(into.entityClass)) from an already committed \(Internals.typeName(self))."
@@ -82,8 +84,10 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
- parameter object: the `NSManagedObject` or `CoreStoreObject` to be edited
- returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`.
*/
public override func edit<O: DynamicObject>(_ object: O?) -> O? {
public override func edit<O: DynamicObject>(
_ object: O?
) -> O? {
Internals.assert(
!self.isCommitted,
"Attempted to update an entity of type \(Internals.typeName(object)) from an already committed \(Internals.typeName(self))."
@@ -99,8 +103,11 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
- parameter objectID: the `NSManagedObjectID` for the object to be edited
- returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`.
*/
public override func edit<O>(_ into: Into<O>, _ objectID: NSManagedObjectID) -> O? {
public override func edit<O>(
_ into: Into<O>,
_ objectID: NSManagedObjectID
) -> O? {
Internals.assert(
!self.isCommitted,
"Attempted to update an entity of type \(Internals.typeName(into.entityClass)) from an already committed \(Internals.typeName(self))."
@@ -114,7 +121,9 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
- parameter objectIDs: the `NSManagedObjectID`s of the objects to delete
*/
public override func delete<S: Sequence>(objectIDs: S) where S.Iterator.Element: NSManagedObjectID {
public override func delete<S: Sequence>(
objectIDs: S
) where S.Iterator.Element: NSManagedObjectID {
Internals.assert(
!self.isCommitted,
@@ -130,7 +139,10 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
- parameter object: the `ObjectRepresentation` representing an `NSManagedObject` or `CoreStoreObject` to be deleted
- parameter objects: other `ObjectRepresentation`s representing `NSManagedObject`s or `CoreStoreObject`s to be deleted
*/
public override func delete<O: ObjectRepresentation>(_ object: O?, _ objects: O?...) {
public override func delete<O: ObjectRepresentation>(
_ object: O?,
_ objects: O?...
) {
Internals.assert(
!self.isCommitted,
@@ -145,7 +157,9 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
- parameter objects: the `ObjectRepresenation`s representing `NSManagedObject`s or `CoreStoreObject`s to be deleted
*/
public override func delete<S: Sequence>(_ objects: S) where S.Iterator.Element: ObjectRepresentation {
public override func delete<S: Sequence>(
_ objects: S
) where S.Iterator.Element: ObjectRepresentation {
Internals.assert(
!self.isCommitted,
@@ -173,8 +187,13 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
)
}
internal func autoCommit(_ completion: @escaping (_ hasChanges: Bool, _ error: CoreStoreError?) -> Void) {
internal func autoCommit(
_ completion: @escaping (
_ hasChanges: Bool,
_ error: CoreStoreError?
) -> Void
) {
self.isCommitted = true
let group = DispatchGroup()
group.enter()