Skip to content

Commit

Permalink
Updated ModelStorage extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Aug 17, 2023
1 parent 3d3e049 commit 90f88ff
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Sources/CoreModel/Store.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ public struct ModelData: Equatable, Hashable, Identifiable, Codable {
public extension ModelStorage {

/// Fetch managed object.
func fetch<T>(_ entity: T.Type, for id: ObjectID) async throws -> T? where T: Entity {
guard let model = try await fetch(T.entityName, for: id) else {
func fetch<T>(_ entity: T.Type, for id: T.ID) async throws -> T? where T: Entity {
let objectID = ObjectID(rawValue: id.description)
guard let model = try await fetch(T.entityName, for: objectID) else {
return nil
}
return try T.init(from: model)
Expand Down Expand Up @@ -115,7 +116,8 @@ public extension ModelStorage {
}

/// Delete the specified managed object.
func delete<T>(_ entity: T.Type, for id: ObjectID) async throws where T: Entity {
try await delete(T.entityName, for: id)
func delete<T>(_ entity: T.Type, for id: T.ID) async throws where T: Entity {
let objectID = ObjectID(rawValue: id.description)
try await delete(T.entityName, for: objectID)
}
}

0 comments on commit 90f88ff

Please sign in to comment.