Skip to content

Commit 311edfe

Browse files
authored
Merge pull request #43 from roanutil/feature/format-and-lint
Run swiftformat
2 parents d7b90d1 + c03c9f4 commit 311edfe

22 files changed

+89
-88
lines changed

Examples/Relationships/RelationshipsExample/RelationshipsExample/FileCabinetDetailView.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct FileCabinetDetailView: View {
2121
)
2222
}
2323

24-
@ViewBuilder @MainActor
24+
@MainActor
2525
private func sidebar() -> some View {
2626
VStack {
2727
Text(viewModel.state.fileCabinet.id.uuidString)
@@ -44,12 +44,12 @@ struct FileCabinetDetailView: View {
4444
}
4545
}
4646

47-
@ViewBuilder @MainActor
47+
@MainActor
4848
private func content() -> some View {
4949
EmptyView()
5050
}
5151

52-
@ViewBuilder @MainActor
52+
@MainActor
5353
private func detail() -> some View {
5454
EmptyView()
5555
}

Examples/Relationships/RelationshipsExample/RelationshipsExample/FileCabinetsView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct FileCabinetsView: View {
2121
)
2222
}
2323

24-
@ViewBuilder @MainActor
24+
@MainActor
2525
private func sidebar() -> some View {
2626
VStack {
2727
Button(
@@ -55,7 +55,7 @@ struct FileCabinetsView: View {
5555
}
5656
}
5757

58-
@ViewBuilder @MainActor
58+
@MainActor
5959
private func detail() -> some View {
6060
EmptyView()
6161
}

Sources/CoreDataRepository/CoreDataBatchError.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Foundation
1111
/// Batch operations that do not use `NSBatch*Request` are not atomic. Some operations may succeed while others fail. If
1212
/// multiple errors are returned, it would
1313
/// be helpful if each error is associated with the input data for the operation.
14-
public struct CoreDataBatchError<T>: Error where T: Sendable {
14+
public struct CoreDataBatchError<T: Sendable>: Error {
1515
/// The input data used for the batched operation. Usually an ``UnmanagedModel`` instance or URL encoded
1616
/// NSManagedObjectID.
1717
public let item: T

Sources/CoreDataRepository/CoreDataRepository+Aggregate.swift

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ extension CoreDataRepository {
1919
}
2020

2121
@inlinable
22-
public func aggregate<Value>(
22+
public func aggregate<Value: Numeric & Sendable>(
2323
function: AggregateFunction,
2424
predicate: NSPredicate,
2525
entityDesc: NSEntityDescription,
2626
attributeDesc: NSAttributeDescription,
2727
groupBy: NSAttributeDescription? = nil,
2828
as valueType: Value.Type
29-
) async -> Result<Value, CoreDataError> where Value: Numeric, Value: Sendable {
29+
) async -> Result<Value, CoreDataError> {
3030
switch function {
3131
case .count:
3232
await count(predicate: predicate, entityDesc: entityDesc, as: valueType)
@@ -46,13 +46,13 @@ extension CoreDataRepository {
4646

4747
/// Get the average of a managed object's numeric property for all instances that satisfy the predicate.
4848
@inlinable
49-
public func average<Value>(
49+
public func average<Value: Numeric & Sendable>(
5050
predicate: NSPredicate,
5151
entityDesc: NSEntityDescription,
5252
attributeDesc: NSAttributeDescription,
5353
groupBy: NSAttributeDescription? = nil,
5454
as _: Value.Type
55-
) async -> Result<Value, CoreDataError> where Value: Numeric, Value: Sendable {
55+
) async -> Result<Value, CoreDataError> {
5656
await Self.send(
5757
function: .average,
5858
context: Transaction.current?.context ?? context,
@@ -65,13 +65,13 @@ extension CoreDataRepository {
6565

6666
/// Subscribe to the average of a managed object's numeric property for all instances that satisfy the predicate.
6767
@inlinable
68-
public func averageSubscription<Value>(
68+
public func averageSubscription<Value: Numeric & Sendable>(
6969
predicate: NSPredicate,
7070
entityDesc: NSEntityDescription,
7171
attributeDesc: NSAttributeDescription,
7272
groupBy: NSAttributeDescription? = nil,
7373
as _: Value.Type
74-
) -> AsyncStream<Result<Value, CoreDataError>> where Value: Numeric, Value: Sendable {
74+
) -> AsyncStream<Result<Value, CoreDataError>> {
7575
AsyncStream { continuation in
7676
let subscription = AggregateSubscription(
7777
function: .average,
@@ -91,13 +91,13 @@ extension CoreDataRepository {
9191

9292
/// Subscribe to the average of a managed object's numeric property for all instances that satisfy the predicate.
9393
@inlinable
94-
public func averageThrowingSubscription<Value>(
94+
public func averageThrowingSubscription<Value: Numeric & Sendable>(
9595
predicate: NSPredicate,
9696
entityDesc: NSEntityDescription,
9797
attributeDesc: NSAttributeDescription,
9898
groupBy: NSAttributeDescription? = nil,
9999
as _: Value.Type
100-
) -> AsyncThrowingStream<Value, Error> where Value: Numeric, Value: Sendable {
100+
) -> AsyncThrowingStream<Value, Error> {
101101
AsyncThrowingStream { continuation in
102102
let subscription = AggregateThrowingSubscription(
103103
function: .average,
@@ -119,11 +119,11 @@ extension CoreDataRepository {
119119

120120
/// Get the count or quantity of managed object instances that satisfy the predicate.
121121
@inlinable
122-
public func count<Value>(
122+
public func count<Value: Numeric & Sendable>(
123123
predicate: NSPredicate,
124124
entityDesc: NSEntityDescription,
125125
as _: Value.Type
126-
) async -> Result<Value, CoreDataError> where Value: Numeric, Value: Sendable {
126+
) async -> Result<Value, CoreDataError> {
127127
await context.performInChild { scratchPad in
128128
do {
129129
let request = try NSFetchRequest<NSDictionary>
@@ -140,11 +140,11 @@ extension CoreDataRepository {
140140

141141
/// Subscribe to the count or quantity of managed object instances that satisfy the predicate.
142142
@inlinable
143-
public func countSubscription<Value>(
143+
public func countSubscription<Value: Numeric & Sendable>(
144144
predicate: NSPredicate,
145145
entityDesc: NSEntityDescription,
146146
as _: Value.Type
147-
) -> AsyncStream<Result<Value, CoreDataError>> where Value: Numeric, Value: Sendable {
147+
) -> AsyncStream<Result<Value, CoreDataError>> {
148148
AsyncStream { continuation in
149149
let subscription = CountSubscription(
150150
context: context.childContext(),
@@ -161,11 +161,11 @@ extension CoreDataRepository {
161161

162162
/// Subscribe to the count or quantity of managed object instances that satisfy the predicate.
163163
@inlinable
164-
public func countThrowingSubscription<Value>(
164+
public func countThrowingSubscription<Value: Numeric & Sendable>(
165165
predicate: NSPredicate,
166166
entityDesc: NSEntityDescription,
167167
as _: Value.Type
168-
) -> AsyncThrowingStream<Value, Error> where Value: Numeric, Value: Sendable {
168+
) -> AsyncThrowingStream<Value, Error> {
169169
AsyncThrowingStream { continuation in
170170
let subscription = CountThrowingSubscription(
171171
context: context.childContext(),
@@ -184,13 +184,13 @@ extension CoreDataRepository {
184184

185185
/// Get the max or maximum of a managed object's numeric property for all instances that satisfy the predicate.
186186
@inlinable
187-
public func max<Value>(
187+
public func max<Value: Numeric & Sendable>(
188188
predicate: NSPredicate,
189189
entityDesc: NSEntityDescription,
190190
attributeDesc: NSAttributeDescription,
191191
groupBy: NSAttributeDescription? = nil,
192192
as _: Value.Type
193-
) async -> Result<Value, CoreDataError> where Value: Numeric, Value: Sendable {
193+
) async -> Result<Value, CoreDataError> {
194194
await Self.send(
195195
function: .max,
196196
context: Transaction.current?.context ?? context,
@@ -204,13 +204,13 @@ extension CoreDataRepository {
204204
/// Subscribe to the max or maximum of a managed object's numeric property for all instances that satisfy the
205205
/// predicate.
206206
@inlinable
207-
public func maxSubscription<Value>(
207+
public func maxSubscription<Value: Numeric & Sendable>(
208208
predicate: NSPredicate,
209209
entityDesc: NSEntityDescription,
210210
attributeDesc: NSAttributeDescription,
211211
groupBy: NSAttributeDescription? = nil,
212212
as _: Value.Type
213-
) -> AsyncStream<Result<Value, CoreDataError>> where Value: Numeric, Value: Sendable {
213+
) -> AsyncStream<Result<Value, CoreDataError>> {
214214
AsyncStream { continuation in
215215
let subscription = AggregateSubscription(
216216
function: .max,
@@ -231,13 +231,13 @@ extension CoreDataRepository {
231231
/// Subscribe to the max or maximum of a managed object's numeric property for all instances that satisfy the
232232
/// predicate.
233233
@inlinable
234-
public func maxThrowingSubscription<Value>(
234+
public func maxThrowingSubscription<Value: Numeric & Sendable>(
235235
predicate: NSPredicate,
236236
entityDesc: NSEntityDescription,
237237
attributeDesc: NSAttributeDescription,
238238
groupBy: NSAttributeDescription? = nil,
239239
as _: Value.Type
240-
) -> AsyncThrowingStream<Value, Error> where Value: Numeric, Value: Sendable {
240+
) -> AsyncThrowingStream<Value, Error> {
241241
AsyncThrowingStream { continuation in
242242
let subscription = AggregateThrowingSubscription(
243243
function: .max,
@@ -259,13 +259,13 @@ extension CoreDataRepository {
259259

260260
/// Get the min or minimum of a managed object's numeric property for all instances that satisfy the predicate.
261261
@inlinable
262-
public func min<Value>(
262+
public func min<Value: Numeric & Sendable>(
263263
predicate: NSPredicate,
264264
entityDesc: NSEntityDescription,
265265
attributeDesc: NSAttributeDescription,
266266
groupBy: NSAttributeDescription? = nil,
267267
as _: Value.Type
268-
) async -> Result<Value, CoreDataError> where Value: Numeric, Value: Sendable {
268+
) async -> Result<Value, CoreDataError> {
269269
await Self.send(
270270
function: .min,
271271
context: Transaction.current?.context ?? context,
@@ -279,13 +279,13 @@ extension CoreDataRepository {
279279
/// Subscribe to the min or minimum of a managed object's numeric property for all instances that satisfy the
280280
/// predicate.
281281
@inlinable
282-
public func minSubscription<Value>(
282+
public func minSubscription<Value: Numeric & Sendable>(
283283
predicate: NSPredicate,
284284
entityDesc: NSEntityDescription,
285285
attributeDesc: NSAttributeDescription,
286286
groupBy: NSAttributeDescription? = nil,
287287
as _: Value.Type
288-
) -> AsyncStream<Result<Value, CoreDataError>> where Value: Numeric, Value: Sendable {
288+
) -> AsyncStream<Result<Value, CoreDataError>> {
289289
AsyncStream { continuation in
290290
let subscription = AggregateSubscription(
291291
function: .min,
@@ -306,13 +306,13 @@ extension CoreDataRepository {
306306
/// Subscribe to the min or minimum of a managed object's numeric property for all instances that satisfy the
307307
/// predicate.
308308
@inlinable
309-
public func minThrowingSubscription<Value>(
309+
public func minThrowingSubscription<Value: Numeric & Sendable>(
310310
predicate: NSPredicate,
311311
entityDesc: NSEntityDescription,
312312
attributeDesc: NSAttributeDescription,
313313
groupBy: NSAttributeDescription? = nil,
314314
as _: Value.Type
315-
) -> AsyncThrowingStream<Value, Error> where Value: Numeric, Value: Sendable {
315+
) -> AsyncThrowingStream<Value, Error> {
316316
AsyncThrowingStream { continuation in
317317
let subscription = AggregateThrowingSubscription(
318318
function: .min,
@@ -334,13 +334,13 @@ extension CoreDataRepository {
334334

335335
/// Get the sum of a managed object's numeric property for all instances that satisfy the predicate.
336336
@inlinable
337-
public func sum<Value>(
337+
public func sum<Value: Numeric & Sendable>(
338338
predicate: NSPredicate,
339339
entityDesc: NSEntityDescription,
340340
attributeDesc: NSAttributeDescription,
341341
groupBy: NSAttributeDescription? = nil,
342342
as _: Value.Type
343-
) async -> Result<Value, CoreDataError> where Value: Numeric, Value: Sendable {
343+
) async -> Result<Value, CoreDataError> {
344344
await Self.send(
345345
function: .sum,
346346
context: Transaction.current?.context ?? context,
@@ -353,13 +353,13 @@ extension CoreDataRepository {
353353

354354
/// Subscribe to the sum of a managed object's numeric property for all instances that satisfy the predicate.
355355
@inlinable
356-
public func sumSubscription<Value>(
356+
public func sumSubscription<Value: Numeric & Sendable>(
357357
predicate: NSPredicate,
358358
entityDesc: NSEntityDescription,
359359
attributeDesc: NSAttributeDescription,
360360
groupBy: NSAttributeDescription? = nil,
361361
as _: Value.Type
362-
) -> AsyncStream<Result<Value, CoreDataError>> where Value: Numeric, Value: Sendable {
362+
) -> AsyncStream<Result<Value, CoreDataError>> {
363363
AsyncStream { continuation in
364364
let subscription = AggregateSubscription(
365365
function: .sum,
@@ -379,13 +379,13 @@ extension CoreDataRepository {
379379

380380
/// Subscribe to the sum of a managed object's numeric property for all instances that satisfy the predicate.
381381
@inlinable
382-
public func sumThrowingSubscription<Value>(
382+
public func sumThrowingSubscription<Value: Numeric & Sendable>(
383383
predicate: NSPredicate,
384384
entityDesc: NSEntityDescription,
385385
attributeDesc: NSAttributeDescription,
386386
groupBy: NSAttributeDescription? = nil,
387387
as _: Value.Type
388-
) -> AsyncThrowingStream<Value, Error> where Value: Numeric, Value: Sendable {
388+
) -> AsyncThrowingStream<Value, Error> {
389389
AsyncThrowingStream { continuation in
390390
let subscription = AggregateThrowingSubscription(
391391
function: .sum,
@@ -405,10 +405,10 @@ extension CoreDataRepository {
405405

406406
// MARK: Internals
407407

408-
private static func aggregate<Value>(
408+
private static func aggregate<Value: Numeric & Sendable>(
409409
context: NSManagedObjectContext,
410410
request: NSFetchRequest<NSDictionary>
411-
) throws -> Value where Value: Numeric, Value: Sendable {
411+
) throws -> Value {
412412
let result = try context.fetch(request)
413413
guard let value: Value = result.asAggregateValue() else {
414414
throw CoreDataError.fetchedObjectFailedToCastToExpectedType
@@ -417,14 +417,14 @@ extension CoreDataRepository {
417417
}
418418

419419
@usableFromInline
420-
static func send<Value>(
420+
static func send<Value: Numeric & Sendable>(
421421
function: AggregateFunction,
422422
context: NSManagedObjectContext,
423423
predicate: NSPredicate,
424424
entityDesc: NSEntityDescription,
425425
attributeDesc: NSAttributeDescription,
426426
groupBy: NSAttributeDescription? = nil
427-
) async -> Result<Value, CoreDataError> where Value: Numeric, Value: Sendable {
427+
) async -> Result<Value, CoreDataError> {
428428
guard entityDesc == attributeDesc.entity else {
429429
return .failure(.propertyDoesNotMatchEntity)
430430
}
@@ -437,8 +437,7 @@ extension CoreDataRepository {
437437
groupBy: groupBy
438438
)
439439
do {
440-
let value: Value = try Self.aggregate(context: scratchPad, request: request)
441-
return value
440+
return try Self.aggregate(context: scratchPad, request: request)
442441
} catch let error as CocoaError {
443442
throw CoreDataError.cocoa(error)
444443
} catch {

Sources/CoreDataRepository/CoreDataRepository+Create_Batch.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ extension CoreDataRepository {
4141
return await context.performInScratchPad(schedule: .enqueued) { [context] scratchPad in
4242
scratchPad.transactionAuthor = transactionAuthor
4343
let objects = try items.map { item in
44-
let object = try item.asManagedModel(in: scratchPad)
45-
return object
44+
try item.asManagedModel(in: scratchPad)
4645
}
4746
try scratchPad.save()
4847
if notTransaction {

Sources/CoreDataRepository/CoreDataRepository+Delete_Batch.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ extension CoreDataRepository {
5353
///
5454
/// This operation is non-atomic. Each instance may succeed or fail individually.
5555
@inlinable
56-
public func delete<Model>(
56+
public func delete<Model: ReadableUnmanagedModel>(
5757
_ items: [Model],
5858
transactionAuthor: String? = nil
59-
) async -> (success: [Model], failed: [CoreDataBatchError<Model>]) where Model: ReadableUnmanagedModel {
59+
) async -> (success: [Model], failed: [CoreDataBatchError<Model>]) {
6060
var successes = [Model]()
6161
var failures = [CoreDataBatchError<Model>]()
6262
for item in items {

Sources/CoreDataRepository/CoreDataRepository+Fetch.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ extension CoreDataRepository {
6060

6161
/// Fetch items from the store with a ``NSFetchRequest`` and transform the results.
6262
@inlinable
63-
public func fetch<Managed, Output>(
63+
public func fetch<Managed: NSManagedObject, Output>(
6464
request: NSFetchRequest<Managed>,
6565
operation: @escaping (_ results: [Managed]) throws -> Output
66-
) async -> Result<Output, CoreDataError> where Managed: NSManagedObject {
66+
) async -> Result<Output, CoreDataError> {
6767
let context = Transaction.current?.context ?? context
6868
return await context.performInChild { fetchContext in
6969
try operation(fetchContext.fetch(request))

0 commit comments

Comments
 (0)