Get a framework's Bundle Identifier programmatically

2.8k Views Asked by At

For logging purposes, I need to know the bundle identifier of the framework I am developing. I do not want to use a static string.

It is easy to access the bundle identifier of the app the framework is running in:

    var appBundleIdentifier = Bundle.main.bundleIdentifier

But I would like the bundle identifier of the framework like ("com.example.my-super-powerful-framework").

1

There are 1 best solutions below

1
Omer Faruk Ozturk On BEST ANSWER

You can access bundle identifier of an object like below;

let bundle = Bundle(for: AFrameworkClass.self)
let bundleId = bundle.bundleIdentifier