How do I get the path of the "/Library/Containers/" directory

Viewed 451

A sandboxed MacOS app can easily access data in two folders ...

  1. ~/Library/Containers/ProgramName/
  2. ~/Library/Group Containers/SecurityGroupName/

The following code will give me the "~/Library/Group Container/" path ...

let fileManager = FileManager.default
let directory = fileManager.containerURL(forSecurityApplicationGroupIdentifier: "myGroup")
print("path:",directory)

This will print: "path: /Users/myName/Library/Group Containers/myGroup"

I want to get the path of the "~/Library/Containers/" directory, not the "~/Library/Group Containers/" directory.

This must be easy to do, as it is a common directory.

Does anybody know how to do this using a swift function.

I know I can just create it with ...

var path: String = "/Users/etc/Containers/" + programName

Ian

1 Answers

In the sandbox the API

let url = try FileManager.default.url(for: .libraryDirectory,
                                      in: .userDomainMask,
                                      appropriateFor: nil,
                                      create: false)

points to the user library of the container of the current app.

file:///Users/myself/Library/Containers/com.myself.Greatapp/Data/Library/

You don't have access to the higher level folder ~/Library/Containers

Related