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?

Accepted Reply

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

Replies

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?

  • My code is

    let dialogURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first print(dialogURL) and the result is

    Optional(file:///Users/patricerapaport/Library/Containers/PR.medical/Data/Documents/)

Add a Comment

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…

  • Yes my App is sandboxes, and permission is OK in the signing capabilities of the App (I will read the link you posted)

Add a Comment

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)

  • Close the thread by marking the correct answer.

Add a Comment

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