When creating a folder in the code, it prompts that the file creation is successful, but when the folder does not exist in the "Download Container" file, do you have any permissions when creating the folder in VisionOS?
static func getFileManager() -> URL {
let documentsDirectory = FileManager.default.urls(
for: .documentDirectory,
in: .userDomainMask
).first!
return documentsDirectory.appendingPathComponent("SGKJ_LIBRARY")
}
static func createFileLibrary() {
let folderUrl = getFileManager()
let fileManager = FileManager.default
do {
try fileManager.createDirectory(
at: folderUrl,
withIntermediateDirectories: true,
attributes: nil
)
print("Folder created successfully: \(folderUrl.path)")
} catch {
print("Failed to create folder: \(error.localizedDescription)")
}
}
I’d like to clarify the problem you’re reporting here. My understanding is that you’re seeing this:
-
You put that code into an app and run it.
-
It’s able to successfully create the directory, meaning you see the
Folder created successfully
output. -
You then stop the app.
-
In Xcode, you go to the Devices and Simulators window.
-
Select the Devices tab.
-
Select your device on the left.
-
Select your app in the Installed Apps list.
-
And from the action (
…
) menu, choose Download Container. -
In the Finder, you select the resulting
.xcappdata
. -
And control-click it and choose Show Package Containers.
-
You explore the container’s content but fail to find the
SGKJ_LIBRARY
directory.
Is that right?
If so, I think that’s expected. Well, more like working as designed. The Download Container facility doesn’t include empty folders.
If you add this to your code:
let file = folderUrl.appending(component: "test.txt")
try "\(Date())".write(to: file, atomically: true, encoding: .utf8)
the test.txt
is present in the downloaded container, bringing with it the parent SGKJ_LIBRARY
directory.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"