# Document-based SwiftUI app question about SwiftData

**URL:** <https://ifnotnil.com/t/document-based-swiftui-app-question-about-swiftdata/4458>\
**Category:** Swift\
**Tags:** swift\
**Created:** [6 September 2025 13:18 UTC](https://ifnotnil.com/t/document-based-swiftui-app-question-about-swiftdata/4458 "2025-09-06T13:18:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DrScott](https://ifnotnil.com/user_avatar/ifnotnil.com/drscott/32/1465_2.png) [@DrScott](https://ifnotnil.com/u/DrScott)\
**Post date:** [6 September 2025 13:18 UTC](https://ifnotnil.com/t/document-based-swiftui-app-question-about-swiftdata/4458/1 "2025-09-06T13:18:10Z")

</div>

I’m about to convert my ray-tracing app to a document-based app so users can multitask with more than one ray-tracing window at a time.

In the current single-window app, I use SwiftData to allow the app to persist its state between launches so the user can return to the same place he or she was at when they last quit the app.

However, I can’t seem to find any info about how to do this for a document-based app. Do I need to persist the document file names and locations so the app will launch with those files ready to use again? Or does the document framework code itself do this for me? Or should the app just launch without open files?

I’d appreciate some advice here. Thanks.

---

<div class="post-metadata">

**Author:** ![samRowlands](https://ifnotnil.com/user_avatar/ifnotnil.com/samrowlands/32/121_2.png) [@samRowlands](https://ifnotnil.com/u/samRowlands)\
**Post date:** [7 September 2025 01:55 UTC](https://ifnotnil.com/t/document-based-swiftui-app-question-about-swiftdata/4458/2 "2025-09-07T01:55:02Z")

</div>

I’ve not done any work with SwiftData, but for document based apps, you just make sure you fill in how to open the document and how to save the document, the rest is taken care of for you.

A quick Google turned up these.

> **[Building a document-based app using SwiftData | Apple Developer Documentation](https://developer.apple.com/documentation/SwiftUI/Building-a-document-based-app-using-SwiftData)**
>
> Code along with the WWDC presenter to transform an app with SwiftData.

> **[How to create a document-based app with SwiftData - a free SwiftData by...](https://www.hackingwithswift.com/quick-start/swiftdata/how-to-create-a-document-based-app-with-swiftdata)**
>
> Learn Swift coding for iOS with these free tutorials

---

<div class="post-metadata">

**Author:** ![DrScott](https://ifnotnil.com/user_avatar/ifnotnil.com/drscott/32/1465_2.png) [@DrScott](https://ifnotnil.com/u/DrScott)\
**Post date:** [7 September 2025 02:23 UTC](https://ifnotnil.com/t/document-based-swiftui-app-question-about-swiftdata/4458/3 "2025-09-07T02:23:20Z")

</div>

Thanks, Sam. I’d read the Apple documentation, but somehow missed the Hacking with Swift article, which is more helpful, even though I visit that site often. I can get really stupid some migraine days.

---

<div class="post-metadata">

**Author:** ![markus](https://ifnotnil.com/letter_avatar_proxy/v4/letter/m/b782af/32.png) [@markus](https://ifnotnil.com/u/markus)\
**Post date:** [7 September 2025 07:23 UTC](https://ifnotnil.com/t/document-based-swiftui-app-question-about-swiftdata/4458/4 "2025-09-07T07:23:20Z")

</div>

Yes - Hacking with Swift, the lesson ‘ **How to create a document-based app with SwiftData’** was for me the key. I created a couple of apps with SwiftData (document based) - with the Apple Documentation only, I’m afraid I would no be able to do this
