I've just updated to Xcode 8 and iOS 10 (using legacy Swift Language Version).
Trying to compile again my project has been an agony, even still using the old Swift syntax. This time one of my functions uses NSBundle(forClass: self.dynamicType)
but now appears that .dynamicType
is deprecated and Xcode doesn't even want to compile it.
His suggestion is to use type(of: self)
but that fails as well. Anyone knows the solution? Thanks.
(The below holds for Swift 3; not legacy Swift Language Version (2.3), however, so it doesn't answer the OP's question, but could be valuable for Swift 3 users, nonetheless)
As noted in your question, dynamicType
is now (Swift 3) deprecated in favour of type(of:)
. In addition:
NSBundle
has been renamed to Bundle
.init(forClass:)
initializer of Bundle
has been renamed to init(for:)
.Taking these changes into account, For Swift 3 you initialize (or fetch an existing instance associated with the specific class) your Bundle
object in the following manner:
class Foo { func bar() -> () { let bundle = Bundle(for: type(of: 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