How to Make Swift, Objective-C and Cocoapods Work Together
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:
Create a new Objective-C header file eg.
tmp.h
in your Watchkit ExtensionWhen prompted, let Xcode automatically configure the project
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.