Skip to content

Commit 305ea11

Browse files
authored
Merge pull request #26 from roanutil/feature/add-inlinable-notations-to-encourage-generic-specialization
Add inlinable notations to public API
2 parents 7a37be3 + 467294e commit 305ea11

25 files changed

Lines changed: 103 additions & 1 deletion

Sources/CoreDataRepository/CoreDataBatchError.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ public struct CoreDataBatchError<T>: Error {
2121
/// The underlying error.
2222
public let error: CoreDataError
2323

24+
@inlinable
2425
public var localizedDescription: String {
2526
error.localizedDescription
2627
}
2728

29+
@inlinable
2830
public init(item: T, error: CoreDataError) {
2931
self.item = item
3032
self.error = error

Sources/CoreDataRepository/CoreDataError.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public enum CoreDataError: Error, Hashable, Sendable {
108108
extension CoreDataError: CustomNSError {
109109
public static let errorDomain: String = "CoreDataRepository"
110110

111+
@inlinable
111112
public var errorCode: Int {
112113
switch self {
113114
case .failedToGetObjectIdFromUrl:
@@ -133,6 +134,7 @@ extension CoreDataError: CustomNSError {
133134

134135
public static let urlUserInfoKey: String = "ObjectIdUrl"
135136

137+
@inlinable
136138
public var errorUserInfo: [String: Any] {
137139
switch self {
138140
case let .failedToGetObjectIdFromUrl(url):

Sources/CoreDataRepository/CoreDataRepository+Aggregate.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ extension CoreDataRepository {
1515
// MARK: Count
1616

1717
/// Get the count or quantity of managed object instances that satisfy the predicate.
18+
@inlinable
1819
public func count<Value: Numeric>(
1920
predicate: NSPredicate,
2021
entityDesc: NSEntityDescription,
@@ -35,6 +36,7 @@ extension CoreDataRepository {
3536
}
3637

3738
/// Subscribe to the count or quantity of managed object instances that satisfy the predicate.
39+
@inlinable
3840
public func countSubscription<Value: Numeric>(
3941
predicate: NSPredicate,
4042
entityDesc: NSEntityDescription,
@@ -55,6 +57,7 @@ extension CoreDataRepository {
5557
}
5658

5759
/// Subscribe to the count or quantity of managed object instances that satisfy the predicate.
60+
@inlinable
5861
public func countThrowingSubscription<Value: Numeric>(
5962
predicate: NSPredicate,
6063
entityDesc: NSEntityDescription,
@@ -77,6 +80,7 @@ extension CoreDataRepository {
7780
// MARK: Sum
7881

7982
/// Get the sum of a managed object's numeric property for all instances that satisfy the predicate.
83+
@inlinable
8084
public func sum<Value: Numeric>(
8185
predicate: NSPredicate,
8286
entityDesc: NSEntityDescription,
@@ -95,6 +99,7 @@ extension CoreDataRepository {
9599
}
96100

97101
/// Subscribe to the sum of a managed object's numeric property for all instances that satisfy the predicate.
102+
@inlinable
98103
public func sumSubscription<Value: Numeric>(
99104
predicate: NSPredicate,
100105
entityDesc: NSEntityDescription,
@@ -120,6 +125,7 @@ extension CoreDataRepository {
120125
}
121126

122127
/// Subscribe to the sum of a managed object's numeric property for all instances that satisfy the predicate.
128+
@inlinable
123129
public func sumThrowingSubscription<Value: Numeric>(
124130
predicate: NSPredicate,
125131
entityDesc: NSEntityDescription,
@@ -147,6 +153,7 @@ extension CoreDataRepository {
147153
// MARK: Average
148154

149155
/// Get the average of a managed object's numeric property for all instances that satisfy the predicate.
156+
@inlinable
150157
public func average<Value: Numeric>(
151158
predicate: NSPredicate,
152159
entityDesc: NSEntityDescription,
@@ -165,6 +172,7 @@ extension CoreDataRepository {
165172
}
166173

167174
/// Subscribe to the average of a managed object's numeric property for all instances that satisfy the predicate.
175+
@inlinable
168176
public func averageSubscription<Value: Numeric>(
169177
predicate: NSPredicate,
170178
entityDesc: NSEntityDescription,
@@ -190,6 +198,7 @@ extension CoreDataRepository {
190198
}
191199

192200
/// Subscribe to the average of a managed object's numeric property for all instances that satisfy the predicate.
201+
@inlinable
193202
public func averageThrowingSubscription<Value: Numeric>(
194203
predicate: NSPredicate,
195204
entityDesc: NSEntityDescription,
@@ -217,6 +226,7 @@ extension CoreDataRepository {
217226
// MARK: Min
218227

219228
/// Get the min or minimum of a managed object's numeric property for all instances that satisfy the predicate.
229+
@inlinable
220230
public func min<Value: Numeric>(
221231
predicate: NSPredicate,
222232
entityDesc: NSEntityDescription,
@@ -236,6 +246,7 @@ extension CoreDataRepository {
236246

237247
/// Subscribe to the min or minimum of a managed object's numeric property for all instances that satisfy the
238248
/// predicate.
249+
@inlinable
239250
public func minSubscription<Value: Numeric>(
240251
predicate: NSPredicate,
241252
entityDesc: NSEntityDescription,
@@ -262,6 +273,7 @@ extension CoreDataRepository {
262273

263274
/// Subscribe to the min or minimum of a managed object's numeric property for all instances that satisfy the
264275
/// predicate.
276+
@inlinable
265277
public func minThrowingSubscription<Value: Numeric>(
266278
predicate: NSPredicate,
267279
entityDesc: NSEntityDescription,
@@ -289,6 +301,7 @@ extension CoreDataRepository {
289301
// MARK: Max
290302

291303
/// Get the max or maximum of a managed object's numeric property for all instances that satisfy the predicate.
304+
@inlinable
292305
public func max<Value: Numeric>(
293306
predicate: NSPredicate,
294307
entityDesc: NSEntityDescription,
@@ -308,6 +321,7 @@ extension CoreDataRepository {
308321

309322
/// Subscribe to the max or maximum of a managed object's numeric property for all instances that satisfy the
310323
/// predicate.
324+
@inlinable
311325
public func maxSubscription<Value: Numeric>(
312326
predicate: NSPredicate,
313327
entityDesc: NSEntityDescription,
@@ -334,6 +348,7 @@ extension CoreDataRepository {
334348

335349
/// Subscribe to the max or maximum of a managed object's numeric property for all instances that satisfy the
336350
/// predicate.
351+
@inlinable
337352
public func maxThrowingSubscription<Value: Numeric>(
338353
predicate: NSPredicate,
339354
entityDesc: NSEntityDescription,
@@ -360,6 +375,7 @@ extension CoreDataRepository {
360375

361376
// MARK: Internals
362377

378+
@usableFromInline
363379
enum AggregateFunction: String {
364380
case count
365381
case sum
@@ -379,7 +395,8 @@ extension CoreDataRepository {
379395
return value
380396
}
381397

382-
private static func send<Value>(
398+
@usableFromInline
399+
static func send<Value>(
383400
function: AggregateFunction,
384401
context: NSManagedObjectContext,
385402
predicate: NSPredicate,

Sources/CoreDataRepository/CoreDataRepository+Batch.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Foundation
1111

1212
extension CoreDataRepository {
1313
/// Execute a NSBatchInsertRequest against the store.
14+
@inlinable
1415
public func insert(
1516
_ request: NSBatchInsertRequest,
1617
transactionAuthor: String? = nil
@@ -29,6 +30,7 @@ extension CoreDataRepository {
2930
/// Create a batch of unmanaged models.
3031
///
3132
/// This operation is non-atomic. Each instance may succeed or fail individually.
33+
@inlinable
3234
public func create<Model: UnmanagedModel>(
3335
_ items: [Model],
3436
transactionAuthor: String? = nil
@@ -68,6 +70,7 @@ extension CoreDataRepository {
6870
}
6971

7072
/// Create a batch of unmanaged models.
73+
@inlinable
7174
public func createAtomically<Model: UnmanagedModel>(
7275
_ items: [Model],
7376
transactionAuthor: String? = nil
@@ -92,6 +95,7 @@ extension CoreDataRepository {
9295
/// Read a batch of unmanaged models.
9396
///
9497
/// This operation is non-atomic. Each instance may succeed or fail individually.
98+
@inlinable
9599
public func read<Model: UnmanagedModel>(
96100
urls: [URL],
97101
as _: Model.Type
@@ -130,6 +134,7 @@ extension CoreDataRepository {
130134
}
131135

132136
/// Read a batch of unmanaged models.
137+
@inlinable
133138
public func readAtomically<Model: UnmanagedModel>(
134139
urls: [URL],
135140
as _: Model.Type
@@ -145,6 +150,7 @@ extension CoreDataRepository {
145150
}
146151

147152
/// Execute a NSBatchUpdateRequest against the store.
153+
@inlinable
148154
public func update(
149155
_ request: NSBatchUpdateRequest,
150156
transactionAuthor: String? = nil
@@ -163,6 +169,7 @@ extension CoreDataRepository {
163169
/// Update the store with a batch of unmanaged models.
164170
///
165171
/// This operation is non-atomic. Each instance may succeed or fail individually.
172+
@inlinable
166173
public func update<Model: UnmanagedModel>(
167174
_ items: [Model],
168175
transactionAuthor: String? = nil
@@ -205,6 +212,7 @@ extension CoreDataRepository {
205212
}
206213

207214
/// Update the store with a batch of unmanaged models.
215+
@inlinable
208216
public func updateAtomically<Model: UnmanagedModel>(
209217
_ items: [Model],
210218
transactionAuthor: String? = nil
@@ -232,6 +240,7 @@ extension CoreDataRepository {
232240
}
233241

234242
/// Execute a NSBatchDeleteRequest against the store.
243+
@inlinable
235244
public func delete(
236245
_ request: NSBatchDeleteRequest,
237246
transactionAuthor: String? = nil
@@ -250,6 +259,7 @@ extension CoreDataRepository {
250259
/// Delete from the store with a batch of unmanaged models.
251260
///
252261
/// This operation is non-atomic. Each instance may succeed or fail individually.
262+
@inlinable
253263
public func delete(
254264
urls: [URL],
255265
transactionAuthor: String? = nil
@@ -289,6 +299,7 @@ extension CoreDataRepository {
289299
}
290300

291301
/// Delete from the store with a batch of unmanaged models.
302+
@inlinable
292303
public func deleteAtomically(
293304
urls: [URL],
294305
transactionAuthor: String? = nil

Sources/CoreDataRepository/CoreDataRepository+CRUD.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Foundation
1111

1212
extension CoreDataRepository {
1313
/// Create an instance in the store.
14+
@inlinable
1415
public func create<Model: UnmanagedModel>(
1516
_ item: Model,
1617
transactionAuthor: String? = nil
@@ -37,6 +38,7 @@ extension CoreDataRepository {
3738
}
3839

3940
/// Read an instance from the store.
41+
@inlinable
4042
public func read<Model: UnmanagedReadOnlyModel>(
4143
_ url: URL,
4244
of _: Model.Type
@@ -50,6 +52,7 @@ extension CoreDataRepository {
5052
}
5153

5254
/// Update the store with an unmanaged model.
55+
@inlinable
5356
public func update<Model: UnmanagedModel>(
5457
_ url: URL,
5558
with item: Model,
@@ -72,6 +75,7 @@ extension CoreDataRepository {
7275
}
7376

7477
/// Delete an instance from the store.
78+
@inlinable
7579
public func delete(
7680
_ url: URL,
7781
transactionAuthor: String? = nil
@@ -93,6 +97,7 @@ extension CoreDataRepository {
9397
}
9498

9599
/// Subscribe to updates of an instance in the store.
100+
@inlinable
96101
public func readSubscription<Model: UnmanagedReadOnlyModel>(_ url: URL, of _: Model.Type)
97102
-> AsyncStream<Result<Model, CoreDataError>>
98103
{
@@ -120,6 +125,7 @@ extension CoreDataRepository {
120125
}
121126

122127
/// Subscribe to updates of an instance in the store.
128+
@inlinable
123129
public func readThrowingSubscription<Model: UnmanagedReadOnlyModel>(_ url: URL, of _: Model.Type)
124130
-> AsyncThrowingStream<Model, Error>
125131
{

Sources/CoreDataRepository/CoreDataRepository+Custom.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ extension CoreDataRepository {
1515
///
1616
/// The caller is responsible for saving the contexts and cleaning up if needed.
1717
/// All this method provides is the contexts and mapping `Error` into ``CoreDataError``.
18+
@inlinable
1819
public func custom<T>(
1920
schedule: NSManagedObjectContext.ScheduledTaskType = .enqueued,
2021
block: @escaping (

Sources/CoreDataRepository/CoreDataRepository+Fetch.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Foundation
1111

1212
extension CoreDataRepository {
1313
/// Fetch items from the store with a ``NSFetchRequest``.
14+
@inlinable
1415
public func fetch<Model: UnmanagedReadOnlyModel>(
1516
_ request: NSFetchRequest<Model.ManagedModel>,
1617
as _: Model.Type
@@ -21,6 +22,7 @@ extension CoreDataRepository {
2122
}
2223

2324
/// Fetch items from the store with a ``NSFetchRequest`` and receive updates as the store changes.
25+
@inlinable
2426
public func fetchSubscription<Model: UnmanagedReadOnlyModel>(
2527
_ request: NSFetchRequest<Model.ManagedModel>,
2628
of _: Model.Type
@@ -39,6 +41,7 @@ extension CoreDataRepository {
3941
}
4042

4143
/// Fetch items from the store with a ``NSFetchRequest`` and receive updates as the store changes.
44+
@inlinable
4245
public func fetchThrowingSubscription<Model: UnmanagedReadOnlyModel>(
4346
_ request: NSFetchRequest<Model.ManagedModel>,
4447
of _: Model.Type
@@ -57,6 +60,7 @@ extension CoreDataRepository {
5760
}
5861

5962
/// Fetch items from the store with a ``NSFetchRequest`` and transform the results.
63+
@inlinable
6064
public func fetch<Managed, Output>(
6165
request: NSFetchRequest<Managed>,
6266
operation: @escaping (_ results: [Managed]) throws -> Output

Sources/CoreDataRepository/CoreDataRepository.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public final class CoreDataRepository {
2929
/// to be performed in.
3030
public let context: NSManagedObjectContext
3131

32+
@inlinable
3233
public init(context: NSManagedObjectContext) {
3334
self.context = context
3435
}

Sources/CoreDataRepository/Internal/AggregateSubscription.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import CoreData
1010
import Foundation
1111

1212
/// Subscription provider that sends updates when an aggregate fetch request changes
13+
@usableFromInline
1314
final class AggregateSubscription<Value>: Subscription<Value, NSDictionary, NSManagedObject> where Value: Numeric {
15+
@usableFromInline
1416
override func fetch() {
1517
frc.managedObjectContext.perform { [weak self, frc, request] in
1618
guard frc.fetchedObjects != nil else {
@@ -37,6 +39,7 @@ final class AggregateSubscription<Value>: Subscription<Value, NSDictionary, NSMa
3739
}
3840
}
3941

42+
@usableFromInline
4043
convenience init(
4144
function: CoreDataRepository.AggregateFunction,
4245
context: NSManagedObjectContext,

Sources/CoreDataRepository/Internal/AggregateThrowingSubscription.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import CoreData
1010
import Foundation
1111

1212
/// Subscription provider that sends updates when an aggregate fetch request changes
13+
@usableFromInline
1314
final class AggregateThrowingSubscription<Value>: ThrowingSubscription<Value, NSDictionary, NSManagedObject>
1415
where Value: Numeric
1516
{
17+
@usableFromInline
1618
override func fetch() {
1719
frc.managedObjectContext.perform { [weak self, frc, request] in
1820
guard frc.fetchedObjects != nil else {
@@ -39,6 +41,7 @@ final class AggregateThrowingSubscription<Value>: ThrowingSubscription<Value, NS
3941
}
4042
}
4143

44+
@usableFromInline
4245
convenience init(
4346
function: CoreDataRepository.AggregateFunction,
4447
context: NSManagedObjectContext,

0 commit comments

Comments
 (0)