Sharing classes between iphone and the apple watch

prawn picture prawn · Feb 5, 2015 · Viewed 7.3k times · Source

I was hoping someone could shed some light on this. I've tried researching but couldn't really find anything...

Is there a way to share a class between the iPhone application and the apple watch extension?

Let's say in the watch extension I have a class myClass; I am unable to use this class within the phone application. Is there anyway to get around this?

Answer

j-techsha picture j-techsha · Feb 10, 2015

iPhone application and the apple watch extension are basally different targets in your project. For each file (except the .h file), you can specify which target you want to include it to.

There are at least two ways to do this.

1) From the top menu select View -> Utilities -> File Inspector. The right panel will show up and you should find the Target Membership section with checkboxes next to the available targets for you project. Check the targets you want to include this file to. In this case, the iPhone app and the WatchKit extension.

2) You can also click on the project to go to the project settings. Select the target you want. (i.e. iPhone app or WatchKit extension), click on the Build Phases tab. In the Compile sources, you can click on the "+" icon to add more files to build for the target. (i.e. myClass.m in your case)

Hope this helps!