Persisting data in a 'Designed for iPad' application

While working through a SwiftUI Tutorial, I found that using:
FileManager.default.url(for:, in:, appropriateFor:, create:)
to locate a directory for persisting some data, does not work on Apple Silicon Macs when building an app for the "My Mac (Designed for iPad)". Quitting the app loses all state saved. Both the iPhone and iPad test devices are able to save and restore state using this method as usual.

Is this the expected behavior? I expected that the M1 platform would be capable of simulating a similar file system for the application.

Targeting macOS, iOS, and iPadOS, what's the simplest method to acquire a valid "Documents" or "Data" directory to persist information across launches and after app updates? (Before going nuclear with CoreData, just hasn't been the most friendly API to work with in my experience so far)

Replies

Were you able to find a fix for this?

I’m not sure what was causing nomonomad’s problem but, in general, iOS apps should be able to locate their documents directory using FileManager on Apple silicon Macs just like they do on iOS devices. If that’s not working for you, please post some details as to what’s going wrong.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Add a Comment