Search code examples
xcodewatchkitwatchos-2

selecting the correct target when creating a new WKInterfaceController


Normally when you create a new WKInterfaceController you just select the WKInterfaceController class and Swift/Obj-C. But the next screen gives you 3 options for choosing the target; iOS app, WatchKit App and WatchKit Extension. It is defaulting to the iOS app for me so I am concerned that maybe I selected the wrong targets for my previous classes.

  1. How do you know what target to select? Is it usually always the WatchKit Extension since that's what we're obviously putting our classes in? It seems obvious I know but I want to make sure because I often get confused with what targets to add binaries, classes and everything else to.

  2. If I have made a mistake in choosing the target for a new WKInterfaceController.swift file where do I fix it? Would I fix it in Build Phases -> Compile Sources?

Apple says here when creating a WKUserNotificationInterfaceController to add it to the WatchKit Extension target. But does that apply to our own custom WKInterfaceController classes as well?

enter image description here


Solution

    1. You'd add it to the WatchKit Extension.

      Notification controller, glance controllers, complication controllers, and interface controllers all run in the extension.

      An interface controller runs in your WatchKit extension and remotely manages the behavior associated with an interface controller in your Watch app’s storyboard file.

    2. If you made a mistake and added it to the wrong group, you'd correct it in that same (Utilities File Inspector) pane, by simply unchecking the wrong target, then checking the proper target.

      enter image description here