Normally, it's pretty easy to load a Bundle
for a class from an instance method:
class SomeClass
func foo() {
let bundle = Bundle(for: type(of: self))
// ...
}
}
But what if we're in a static method?
class SomeClass
static func foo() {
let bundle = Bundle(for: ???)
}
}
I've tried a bunch of stuff like SomeClass.type
, etc, but haven't figured it out.
Also, I'm hoping to use one of the other initializers such as URL or identifier since that's fragile.
Thanks.
Swift 5
static func foo() {
let bundle = Bundle(for: Self.self)
}
You can use ClassName.self.
class SomeClass
static func foo() {
let bundle = Bundle(for: SomeClass.self)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With