Search code examples
iosswiftcocoapodswatchkit

Swift project with cocoapods new errors when watchkit added


I have a working Swift IOS project that uses an Objective C SDK. The SDK code is installed and updated with cocoapods. There is a bridging header file in the Swift project. This project has been compiled and run many times, and is fully operational. And of course, since it has been built and run, the workspace file is how it is opened...

I added a watchkit extension to it. I ran pod update to make a new lock file. I confirmed the search path in the watchkit includes the pods/recursive. I added the header file to Watchkit Extension.

Those three steps are the only suggestions I've been able to find regarding making cocoapods managed code work with Watchkit.

I get three errors. they are:

Undefined symbols for architecture x86_64:

  "_OBJC_CLASS_$_SparkCloud", referenced from:
      __TMaCSo10SparkCloud in InterfaceController.o

  "_OBJC_CLASS_$_SparkDevice", referenced from:
      __TMaCSo11SparkDevice in InterfaceController.o

ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

Does anyone have a suggestion for further steps that may allow the project to compile?


Solution

  • As mentioned in the question, this Swift IOS project uses cocoapods to manage an objective C SDK that provides access to a Cloud API.

    Take these steps after adding the WatchKit Extension to the Xcode project.

    In the project main folder (blue, top) Info tab, note that in the section Debug,there is an entry of None beside the WatchKit Extension. Change this to Pods.debug. Click on it and choose Pods.debug.

    Under the Release section, change the WatchKit Extension from None to Pods.release

    Now click on the WatchKit Extension Target and choose the General tab. Here the Linked Frameworks and Libraries will be empty. Click the plus sign and choose from the list libPods.a and add it, make sure the Required option (to the right) is selected.

    That should finish the job of getting your cocoapods library accessible to the InterfaceController.swift file under WatchKit Extension, which is where you write the code that "runs" the watch.