The interest among developers to start creating WatchKit apps is at an all-time high. We have here outlined the steps for making a basic ‘Hello World’ app for Apple Watch.
A WatchKit lab is currently being organized at the Sunnyvale campus of Apple Inc. Scheduled to run till the 30th of April, it is being flocked by professional developers worldwide – thanks to the opportunity to test their WatchKit apps on the actual device (instead of depending on the Xcode simulator). Experts from app development companies have also confirmed that clients have started asking for separate iOS and WatchKit versions of new apps. If you wish to succeed as a coder for Apple apps, it is imperative for you to start learning how to make WatchKit apps as soon as possible (if you do not have any idea yet, you are already behind the times). Follow these steps to create your very first ‘Hello World’ application with WatchKit:
- Download the latest version of Xcode – WatchKit is supported by Xcode 6.2 and above. If the version you are using is outdated, it’s high time you went for the upgrade. The third beta of Xcode 6.3 is already out (with Swift 1.2 and iOS 8.3 beta) – and iOS app developers recommend using it for making WatchKit apps. You will find the new Xcode version at https://developer.apple.com/xcode/downloads/.
- Create a developer account – That is, of course, if you do not already have one. Both free as well as paid Apple developer accounts can be used for creating and submitting WatchKit applications. If you are an amateur/first-time developer, it is advisable to go for a free account first. You can always move on to a paid developer account later.
- Take a tour of the WatchKit SDK – The last stage of preparations, before you start creating the ‘Hello World’ app. Check out the features/resources present in the WatchKit SDK (built-in with the latest Xcode beta). Once you get a hang of the tool, it will be time to start coding.
- Start with a new Project – Next up, create a new Xcode Project (File → New → Project). If you are an iPhone app developer with any experience, you will be familiar with this step. We have not yet started doing anything exclusively for the app for Apple Watch.
- Adjust the views and settings – Okay, the new Project window is now open, right? On the right hand side, click on ‘Single View Application’. On the other side, make sure ‘iOS application’ is selected (the usual way). Once you’re done, name the project – “Hello World” would be a nice, appropriate name – and save it. Reopen it once – just to make sure that the project has been properly saved.
- Time to add a new target – It’s now time to focus our attention to developing for Watch. App developers would have to create a new target, by clicking on File → New → Target (depending on the Xcode version you are using, a ‘+’ sign might also be visible for adding new targets). In the display window that comes up next, select ‘Watch App’. This would add the WatchKit extension (the element that resides in the paired iPhone) to our code.
- Deactivate Glances and Notifications options – When you are making a full-blown WatchKit app, you will need them – but for a simple ‘Hello World’ app, they are not necessary. Uncheck both of these options to start things off. First-time developers might find that things have got unduly complicated, if these options remain on.
- Check what you see now – Time to take a breather, and see if everything is going as per plans. Provided that you have performed the above steps correctly, you will now see two things: the WatchKit extension (where all the codes would reside, i.e., it will have the interface.storyboard file), and the actual Watch app (which has the app UI (interface controller); stays on the Watch screen). If you cannot see either of the two, repeat all the previous steps from scratch.
- Activate the build scheme now – Next up, initiate the new build scheme in your Xcode project. A common mistake that many iOS app developers make is trying to work with multiple build schemes simultaneously. Do not try this and overcomplicate matters. A single, properly organized build scheme would suffice for your ‘Hello World’ app project.
- Create a new label – With this, you enter the final phase of creating your very first WatchKit app. Navigate to the interface.storyboard in the new target (Watch App) you had created. On the right side, you will find labels – drag-and-drop one on the Watch App. Make sure that the interface has a separator object as well.
- Customize the label – Now that you have added the label, it’s time to customize it properly. Call the setText method (inside the awakeWithContext function), and add the words ‘Hello World’ to it. The label, of course, has to be centered. Otherwise, the alignment of your app (and the text within) would not be correct.
- Make a label outlet – Experts on programming and WatchKit app development opine that this is another important step. You need to create an outlet for the label. Doing so is simple – launch the ‘Assistant Editor’, and you will be able to set up the outlet without any problem.
- Time to run the app – Finally…it’s time to see whether your ‘Hello World’ app is indeed ready to say hello to the world. After selecting the target, click on ‘Run’ (double check whether the correct app name is selected). Choose any of the iOS simulators, to run the application on. According to iPhone app development experts, testing the app on iPhone 5, iPhone 6, and iPhone 6 Plus are an absolute must. After all, these are the devices that would be paired with Apple Watch.
- Check the app on the Watch emulator – And this is the last step. Click on Hardware → External Displays → Apple Watch – 38 mm. This will help you test your app on the Apple Watch emulator (as an External Device). Repeat the process with Hardware → External Displays → Apple Watch – 42 mm. If everything seems okay…congrats! You have just created your first ‘Hello World’ application successfully.
The absence of Auto Layout in the Interface Controller of the Watch App target can be slightly confusing for first-time WatchKit developers. It is also vital to test apps on both an iOS simulator as well as a Watch emulator. The next Apple Watch Hackathon is in June – and you need to start brushing up your expertise with WatchKit development…quickly.