Let's create your first Apple Watch App

It is so much fun and easy 😊

·

2 min read

Why apple watch

Apple watch is number #1 selling smart in the world and the apps that run on the watch has been growing day by day. You can create a stand-alone app that runs solely on the app and you don't need an iPhone to operate the app in any way. We will be using SWIFT which is a multi-purpose compiled programming language and is still relatively new (2014).

Requirements

  • Xcode v13.x
  • Empty watchOS Swift UI project
  • Basic OOP knowledge
  • Laptop

image.png

On the template screen, go to the "WatchOS" tab and hit "Next." Last but not least, give your app a name! The app will be called "build-a-watch-app" in this example. Then click "Next."

image.png

Add code

After you've completed your setup, it's time to add some code. We'll only add a simple UI and an increment method for this demonstration.

Please add the code in your "Content View" file -

import SwiftUI

struct ContentView: View {
    @State private var count = 0

    var body: some View {
        VStack(alignment: .center, spacing: 8) {
            Text("\(count)")
                .font(.system(size: 90))
                .fontWeight(.black)
                .multilineTextAlignment(.center)

            HStack(alignment: .center, spacing: 8) {

                Button {
                    print("Increment")
                    count = count + 1
                } label: {
                    Image(systemName: "plus")
                        .font(.system(size: 34))
                }
                Button {
                    print("Increment")
                } label: {
                    Text("Go!")
                        .font(.system(size: 34))
                }
            }
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

image.png

Conclusion

Congratulations! You've completed the development of your first WatchOS app.

This isn't the most complicated piece of code we'll develop, but it will act as the foundation for all of our WatchOS apps in the future.

We will be adding more functionality in the future so stay tuned for the next post.

Thanks for reading

Â