watchkitapple-watchwatchconnectivityapple-watch-complicationwatchos-5

iOS WatchOS - what is the difference between WatchKit App and WatchKit App extension?


I'm trying to create an iOS WatchOS5 complication and am seeing a number of tutorials and apple documentation. They talk about:

What is the difference between iOS WatchKit App and WatchKit App Extension?

If I want to share data between my phone app and my watch app, do I need both in order to use Watch Connectivity framework?


Solution

  • Current answer (valid from Xcode 14): the separate 2 targets don't exist anymore, the new default watchOS app template combines the WatchKit App and WatchKit App Extension targets into a single Watch App target, which can store both code and resources, similar to iOS app targets.

    See the Xcode 14 release notes (relevant excerpt below).

    Xcode 14 includes a new default template for watchOS apps that combines the WatchKit App and WatchKit App Extension targets into a single Watch App target, simplifying code, asset, and localization management. You can deploy single-target watchOS apps to watchOS 7 and later. (83222217)


    Historical answer (valid up until Xcode 13): The two come hand-in-hand, both are needed to create a watchOS application and you cannot use one without the other.

    The main difference is that a WatchKit App is responsible for displaying the UI, so this is where you store the storyboard(s) and all assets (images, etc) used from storyboards. On the other hand, your WatchKit App Extension is responsible for everything done programatically, so this is where all your interface controllers and other classes should reside. You should also store all assets that you access from code in your App Extension target.

    You'll need to use the WatchConnectivity framework from code as part of your App Extension target, however, as already stated, all watchOS applications need to have a WatchKit App target as well.