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

1

2 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 :)

0

It is pretty simple to get the app ID :

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

A bundle identifier is the string assigned to the CFBundleIdentifier key in the bundle’s Info.plist file. This string is typically formatted using reverse-DNS notation so as to prevent name space conflicts with developers in other companies. For example, a Finder plug-in from Apple might use the string com.apple.Finder.MyGetInfoPlugin as its bundle identifier. Rather than passing a pointer to a bundle object around your code, clients that need a reference to a bundle can simply use the bundle identifier to retrieve it

For more details & other operation's details, please check

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy