Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SwiftDataStore #4

Open
wants to merge 15 commits into
base: work/swift-data-repo-tim
Choose a base branch
from
Open

Conversation

cfoughty7
Copy link
Contributor

No description provided.

@cfoughty7 cfoughty7 requested a review from wtmoose October 2, 2024 17:37
@cfoughty7 cfoughty7 self-assigned this Oct 2, 2024
@@ -17,7 +17,7 @@ public struct DefaultError<UIErrorType: UIError>: AppError {
intent: ErrorIntent = .indispensable
) {
self.uiError = uiError
self.error = error
self.error = error as? NSError
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going to do this, the initializer should specify NSError rather than Error so that other error types don't slip through the cracks. But ideally this would work with any Error. Remind me why we need Equatable?

public func set(key: Key, value: Value?) throws -> Value? {
if let value {
try modelContext.insert(TimestampedValue(key: key, value: value, encoder: encoder))
try modelContext.save()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why save here? By default, I think apps should rely on auto-save. If there's a need to save on every insertion, we can add a configuration option to the store.

// MARK: - Constants

@Model
class TimestampedValue {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd make this a top-level internal type and conform to StoreModel—just for consistency and easier potential reuse.

try evict(for: key)
modelContext.insert(value)
}
try modelContext.save()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same concern about saving


@MainActor
public func clear() async throws {
try modelContext.delete(model: Value.self)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we clear the timestamp store here as well?

private let timestampStore: PersistentStore<Model.Key, UUID>

@MainActor
private var modelContext: ModelContext {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does lazy var not work for this scenario?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants