Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to obtain the app ID programmatically in Swift?

Tags:

swift

app-id

In a macOS app, I'm using this code to create a directory in Application Support folder.

let directoryURL = appSupportURL.appendingPathComponent("com.myCompany.myApp").appendingPathComponent("Documents")

How can the string com.myCompany.myApp obtained programmatically in Swift?

I saw this question but I'm not sure how to use it in my macOS Swift app: Access App Identifier Prefix programmatically

like image 843
Cue Avatar asked May 30 '17 21:05

Cue


1 Answers

if let bundleIdentifier = Bundle.main.bundleIdentifier {
    appSupportURL.appendingPathComponent("\(bundleIdentifier)").appendingPathComponent("Documents")
}

Little explanation: Property bundleIdentifier is optional, therefore you have to safely-unwrap the value and then you won't be asked for any exclamation mark :)

like image 198
Dominik Bucher Avatar answered Nov 10 '22 11:11

Dominik Bucher