How often/ under what circumstances are users sandbox directory URL's changed?
So I tried to save a URL to a document in @AppStorage
@AppStorage(DefaultsKey.userActiveBook.rawValue) var activeBook : URL = Bundle.main.url(forResource: "BookPlaceHolder", withExtension: "pdf")!
When user selects a new document activeBook
is updated with the new URL
.
Issue is when the app relaunches from xCode the path to whatever is stored in activeBook
changes. My work around so far is to just access the users Documents Directory via FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
. Then appending the last path component of activeBook
.
sidebar: obviously this doesn't work if the saved URL
in activeBook
is still the default from Bundle.main.url
. I haven't written that workaround as yet.
Am I only seeing issues in development due to a fresh relaunch via xCode?
If the user only ever terminates the app on their device are the .documentDirectory
URL's changing on each launch or do the remain constant?
I don't want to write a workaround to ensure the correct URL for whats stored in @AppStorage,
if the changing URL's only occurs due to launching from xCode which the end user wont ever encounter that edge case.