mstdn.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
A general-purpose Mastodon server with a 500 character limit. All languages are welcome.

Administered by:

Server stats:

14K
active users

#swiftdata

3 posts2 participants0 posts today
Continued thread

Got it fixed thanks to @freiwald Store the entries in an array and write this array to the parent using append(contentsOf:) at once. Also very important: neither define inverse relations in the child model nor use them for insertion! I am now able to write 200k entries in 37s.

#SwiftData

Using #SwiftData and you're instantiating your container inline with the Window creation something like this:

WindowGroup {
MyView()
}
.modelContainer(myModelContainer())

Will work fine on a Mac. The same thing on iOS will fail if you rotate the device or otherwise cause the Window to be recreated. The model context will be reset/recreated throwing an error.

Instantiate the container in your structure and pass that instead and all is good.

Ask me how I know?

Found another bug in #SwiftData and submitted Feedback this time with a Swift Testing suite to see if that helps get it fixed faster:

FB17593538: Inserted child model loses its relation to parent upon save if a fetch for the parent is done using includePendingChanges false in between insert and save

github.com/feedback-assistant/

Note: Core Data can do this without issue.

Submission Date 2025-05-13 Status Open Area SwiftData Operating System Version macOS 15.4 Type Incorrect/Unexpected Behavior Description My app is dependent on using includePendingChanges false on ...
GitHubFB17593538: Inserted child model loses its relation to parent upon save if a fetch for the parent is done using includePendingChanges false in between insert and save · Issue #658 · feedback-assistant/reportsBy malhal