Skip to content

Describe precisely what isPersisted checks - #22

Merged
Jeehut merged 2 commits into
mainfrom
wip/ispersisted-docs
Oct 15, 2026
Merged

Jeehut merged 2 commits into
mainfrom
wip/ispersisted-docs

Conversation

@Jeehut

@Jeehut Jeehut commented Oct 14, 2026

Copy link
Copy Markdown
Member

Overview

The docs of PersistentModel.isPersisted said it tells whether a model "exists in the database". The property checks modelContext != nil, which is true right after insert(_:), before any save. The docs now say that and point to persistentModelID.isTemporary (iOS 27 and the other OS 27 versions) for the saved state. The example no longer calls insert with try, which does not throw.

Split out of #7.

How this was verified

New PersistentModelExtTests.insertingIsEnoughWithoutSaving with an in-memory ModelContainer: isPersisted is false before the insert and true after it, while the context still has unsaved changes.

✔ Test run with 1 test in 1 suite passed.

No code change, so there is no red run; the test pins the documented behavior.

The documentation said the model "exists in the database", but the
property only checks whether it was inserted into a ModelContext,
which is true before the context is saved. It now says so and points
to persistentModelID.isTemporary for the saved state.
The doc comment now says that isPersisted turns true on insert, before
any save; a test with an in-memory container pins that. The example
also called insert with try, which does not throw.
@Jeehut
Jeehut merged commit c1a9036 into main Oct 15, 2026
5 checks passed
@Jeehut
Jeehut deleted the wip/ispersisted-docs branch October 15, 2026 10:08
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.

1 participant