read

Interoperability is possible with Swift and Objective-C.

Apple has a guide on how to make the same project to use both the languages. The gist is to create a new bridging header.

Add a bridging header

There’s a step-by-step answer to creating the bridging header.

Summary of my steps:

  1. Create a new Objective-C header file eg. tmp.h in your Watchkit Extension

  2. When prompted, let Xcode automatically configure the project

  3. Import your objective-c lib headers in the automatically created bridging header file

With that, you can use the Objective-C code in your Swift code.

You may also delete tmp.h.

Making it work with Cocoapods

At this point, if you are using cocoapods, you will encounter file not found on the import statement.

This is because Cocoapods is not configured for the Watch app extension.

To fix, you click on Project > Info > Configurations > expand the dropdown, and select the corresponding Pods just like how it is for the main app.


Image

@samwize

¯\_(ツ)_/¯

Back to Home