iOS, Swift

Embedding Swift in your Objective-C app, solving the libswiftCore.dylib error

Lately I’ve been experimenting with using Swift in my Titanium projects.  Since Titanium is really just a Objective-C app under the covers it is fairly straight forward to mix and match Swift within your project.

I did encounter one surprise the first time I added a Swift module or extension to my project.  Even though the extension or module compiles without issue, as soon as it was added to my Titanium project I started to receive errors similar to dyld: Library not loaded: @path/libswiftCore.dylib.  The root cause was surprising, it seems that Xcode 6.2 does not enable the “Embedded Content Contains Swift Code” Build Setting by default for Swift extension projects.

If you are building Swift extensions for Titanium or any other Objective-C application make sure you update your project to include this.  To do this, go to your Swift Target’s Build Settings, then Build Options.  Alternatively you can just search for embed to find the correct option.  Once you have located the setting you need to toggle the “Embedded Content Contains Swift Code” from No to Yes as illustrated below.

xcode-swift-embedded