Swift: How to load a Bundle from a static method

Viewed 2073

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.

2 Answers

Swift 5

static func foo() {
        let bundle = Bundle(for: Self.self)
   }
Related