Posted on

Create your First WatchOS app with Swift 5 and XCode 13.7

Watch the complete tutorial on Youtube: Create your First WatchOS app with Swift 5 and XCode 13.7
Hello and welcome to Todays tutorial . In this tutorial Series we are going to create a simple watchOS app.I will show you some basics of watch OS app that includes how to layout elements and how to code for each Interface.Then we will look at how we can communicate between the watchOS app and the host app.
the first thing we are going to build is a basic counter app . there will be a number label and a plus button.each time you press the plus Button the number gets incremented.

SO first of all open the Xcode and create a new watchOS project.Name it SheheryarWatchOS app so you will remember me 😁.
So our new project is ready to be build up.Here you can see we have three different types of folders .
File Inspector

The first one is WatchOS app that contains appDelegate, SceneDelegate , View Controller , Main.storyboard and Lauchscreen Story board. This is what we all are familiar with . This is the host application that will run on our iPhone for our watchOS app.
next you will see a WatchKit app folder that contains interface.storyboard .This is our storyboard or display for our watch OS app.currently app doesn’t support for the Programmatic UI so we will have to work on these interface Controllers.
Next you will see a WatchKit extention.This folder contains InterfaceController witch is quite similar to our ViewController . This interfaceController controls everything in Interface.storyboard.
Now its time to open each of these files and have a look at them.First open the interface.storyboard and drag a label on the initial interface and set its title to 0.also set its horizontal alightment to center.then add a Button on the initial interface.In the attributes Inspector simply set the Allignment of button to center for both horizontal and vertical Allignment. Change the background color to green. and set the title to “+” symbol.
intial interface

Next step is to connect the Label and button to the interface Controller for IBOutlet and IBAction.create a new variable as
var number:Int = 0
Now inside the IBAction function write
number += 1
numberLabel.setText(text: String(number))

Now its time to test the app.Before running the app make sure you have selected the WatchKit app besides the playbutton .Run the app and you will see your first watchOS app.
One other thing to remember is that You can support running the watchOS app without host app installation in the project inspector by selecting watchKit extention and you will see an option there.

This all for today .Let me know your opinion in comment section.See you in the next tutorial.

One Reply to “Create your First WatchOS app with Swift 5 and XCode 13.7”

Leave a Reply

Your email address will not be published. Required fields are marked *