swift and AppDirectory

I develop an App in macos, and I need to access the documentDirectory:

let dialogURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first

I get: file:///Users//Library/Containers/<*******.appName>/Data/Documents

But in the Library/Containers directory I don't have the <*******.appDirectory> (in my case "PR.medical") but (in my case "medical")

of course, it would be possible to hard code the name of the desired directory, but if in the future apple change anything, my app will not work properly.

Am I missing something?

Answered by Claude31 in 695626022

Close the thread by marking your own answer as correct (click the icon below the 2 arrows).

You say "I get":

file:///Users//Library/Containers/<*******.appName>/Data/Documents

But that isn't a valid path (note the two backslash characters after "Users").
Can you share the correct path?

I guess //Library means /XXXX/Library ?

It is a sandboxed app ? If so, you should then manage the bookmarks. You may read this:

https://stackoverflow.com/questions/31278869/ file-access-in-a-sandboxed-osx-app-with-swift

I tested in a case (with bookmarks) and got the following documentDirectory:

file:///Users/XXXXXXX/Library/Containers/com.yyyyyy.AppName/Data/Documents/

I thought com.yyyyyy.AppName would be the bundle ID, but it is the bundleName.

But this directory does not show in my user/Library… I cannot find where it is…

I'm very sorry, but it seems that file:///Users/patricerapaport/Library/Containers/PR.medical/Data/Documents/ links to file:///Users/patricerapaport/Library/Containers/medical/Data/Documents/

because I wrote this:

let dialogURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first print(dialogURL) var isDir = ObjCBool(false) let exists = FileManager.default.fileExists(atPath: dialogURL!.path, isDirectory: &isDir) print(exists)

and the result for print(exists) is true (I don't know how to close the thread)

Accepted Answer

Close the thread by marking your own answer as correct (click the icon below the 2 arrows).

swift and AppDirectory
 
 
Q