Skip to content

Commit be88b42

Browse files
committed
Add managedFetchRequest to UnmanagedModel for convenient access to fetch requests
3.0-preview
1 parent 2005e68 commit be88b42

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

Sources/CoreDataRepository/UnmanagedModel.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,16 @@ public protocol UnmanagedModel: Equatable {
2727

2828
/// Initialize of new instance of `Self` from an instance of ``ManagedModel``
2929
init(managed: ManagedModel) throws
30+
31+
/// ``NSFetchRequest`` for ``ManagedModel`` with a strongly typed ``NSFetchRequest.ResultType``
32+
static func managedFetchRequest() -> NSFetchRequest<ManagedModel>
33+
}
34+
35+
extension UnmanagedModel {
36+
public static func managedFetchRequest() -> NSFetchRequest<ManagedModel> {
37+
NSFetchRequest<ManagedModel>(
38+
entityName: ManagedModel.entity().name ?? ManagedModel.entity()
39+
.managedObjectClassName
40+
)
41+
}
3042
}

0 commit comments

Comments
 (0)