Skip to content

Instantly share code, notes, and snippets.

@vialyx
Created March 13, 2018 09:11
Show Gist options
  • Save vialyx/6ebbde107de0323c430ffa7c624f25d1 to your computer and use it in GitHub Desktop.
Save vialyx/6ebbde107de0323c430ffa7c624f25d1 to your computer and use it in GitHub Desktop.
// TODO: - This is often used combination in regular projects to get access to project resources
let mainBundle = Bundle.main
print("identifier: \(String(describing: mainBundle.bundleIdentifier))")
// TODO: - Find nessesary bundle, for example by name
let allBundles = Bundle.allBundles
print("bundles: \(allBundles)")
// TODO: - If want to be sure to get bundle for specific class. Use Bundle class initializer.
class User {
var id: UInt
var name: String
init(id: UInt, name: String) {
self.id = id
self.name = name
}
}
let classBundle = Bundle(for: User.self)
print("class bundle: \(classBundle)")
// TODO: - Also you can allocate bundle using itself identifier
let identifierExample = "com.apple.dt.playground.stub.iOS_Simulator.Bundle-FF59A7A5-B1B5-4AEB-AE77-2334AF184375"
let identifiedBundle = Bundle(identifier: identifierExample)
print("identifier bundle: \(String(describing: identifiedBundle))")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment