Contents

Creating Your First Apple Watch Application

1 Star2 Stars3 Stars4 Stars5 Stars (5 votes, average: 5.00 out of 5)
Loading...

Pham Van Hoang, hoangk55cd@gmail.com,Β is the author of this article and he contributes to RobustTechHouse Blog

Introduction

AtΒ WWDC 2015, watchOS2 for apple watch was made public and it came with a lot of new features and capabilities, including a new ability to write native apps that run right on the watch.

In this article we will show you how to create your first watchOS application named β€œStopwatch” using Objective-C. Hooray!

Let’s Get Started

1. Β  Β  Go to Xcode and create new application. Select watchOS -> Application

create first apple watch app_01

2. Β  Β Name the app as β€œStopwatch”. In this project we don’t need notification so just deselect the option β€œInclude Notification Scene”

 create first apple watch app_02

3. Β  Β Create user interface.

In this Stopwatch app, we will have a label to display our time; a start button to trigger (or stop) the timing; a lap button that allows us to record our last lap time; and a label to display it. To do this, head over to theΒ β€œInterface.storyboard” in your Watch Kit App and add attributes as below.

 create first apple watch app_03

β€œThe projects you create for Apple Watch consist of two separate bundles: a Watch app and a WatchKit extension. TheΒ Watch appΒ bundle contains the storyboards and resource files associated with all of your app’s user interfaces. TheΒ WatchKit extensionΒ bundle contains the extension delegate and the controllers for managing those interfaces and for responding to user interactions. While these bundles are distributed inside an iOS app, they are then installed on the user’s Apple Watch and run locally on the watch” Β – Apple docs

To have buttons that sit side-by-side of each other, we need to add them into a Group and configure them as below.

create first apple watch app_04

4. Β  Β Outlets and Actions

The next step we have to take is to link these elements within our app. Go to β€œInterfaceController.h” class and create outlets and actions as below:

#import <WatchKit/WatchKit.h>
#import <Foundation/Foundation.h>

@interface InterfaceController : WKInterfaceController {
    NSTimer *timer; // we use timer to call function update UI every seconds
    NSDate  *startTime; // time that we press start stop watch
    NSString *currentTimeString; // save current time 
    BOOL isStarted; // check whether the timer is currently running
}

@property (strong, nonatomic) IBOutlet WKInterfaceLabel  *currentTimeLabel;
@property (strong, nonatomic) IBOutlet WKInterfaceLabel  *lapTimeLabel;
@property (strong, nonatomic) IBOutlet WKInterfaceButton *startButton;
@property (strong, nonatomic) IBOutlet WKInterfaceButton *lapButton;

- (IBAction)lapTimeButtonPress;
- (IBAction)startTimeButtonPress;

@end

create first apple watch app_05

5. Β  Β Implement the function.

Now head over to file β€œInterfaceController.m” to implement codes that actually update time in our watch application.

First we want to add function that update timer every time we call and reset when user press button stop.

- (void) updateTimer {
    NSDate *dateNow = [NSDate date];
    NSTimeInterval interval = [dateNow timeIntervalSinceDate:startTime];
    NSDate *timeDate = [NSDate dateWithTimeIntervalSince1970:interval];
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"HH:mm:ss"];
    [dateFormat setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0.0]];

    currentTimeString = [dateFormat stringFromDate:timeDate]; // save current time in stop watch
    [self.currentTimeLabel setText:currentTimeString]; // update UI 
}

- (void) resetTimer{ // reset timer when user click stop
    [timer invalidate];
    [self.currentTimeLabel setText:@"00:00:00"];
    [self.lapTimeLabel setHidden:YES];

}


Next, we need to trigger β€œupdate timer” function which update every second using NSTimer. We also need to check whether the timer is currently running or not, so we can disable/enable β€œlap” button and change the button start title to β€œstop/start”.

- (IBAction)startTimeButtonPress {
    isStarted = !isStarted;
    if (isStarted == YES) {
        [self.lapButton setEnabled:YES];
        [self.startButton setTitle:@"Stop"];

        startTime = [NSDate date];
        timer = [NSTimer scheduledTimerWithTimeInterval:1.0
                                                 target:self
                                               selector:@selector(updateTimer)
                                               userInfo:nil
                                                repeats:YES];
    }
    else {
        [self.lapButton setEnabled:NO];
        [self.startButton setTitle:@"Start"];
        [self resetTimer];
    }

}

Lastly, we just need to update β€œlap” label each time user presses on the β€œlap” button.

- (IBAction)lapTimeButtonPress {
    [self.lapTimeLabel setHidden:NO];
    self.lapTimeLabel.text = currentTimeString;
}

We have now completed a basic stopwatch application. Let’s run the project and enjoy your new apple watch app.

create first apple watch app_06

You can find the full example here.Β  Hope you will find this post useful. If you have any questions, please leave the comments below. Thanks for reading.

Reference

Β Apple App Programming Guide for watchOS

Brought to you by the RobustTechHouse team (Singapore based app development company). Β If you like our articles, please also check out our Facebook page.

Recommended Posts
Showing 84 comments
  • fallout 76 hacks
    Reply

    I dugg some of you post as I thought they were very beneficial invaluable

  • Resume101
    Reply

    For professional resume writing, head to Resume101 and examine the prices and packages they offer.

  • Reply

    Thanks for the nice post

  • Reply

    Je ne suis pas vraiment un lecteur Internet pour Γͺtre honnΓͺte mais vos blogs vraiment sympa, continue comme Γ§a ! μ—λ³Όλ£¨μ…˜μΉ΄μ§€λ…Έ Je vais aller de l’avant et ajouter votre site Γ  vos favoris pour revenir Γ  l’avenir. advgamble.com

  • among us
    Reply

    The information about the watch model you pointed to is very interesting. I really like the Apple watch model. It is always my ideal choice and many others!
    coloring pages

  • word hurdle
    Reply

    Thank you very much for the helpful post.

  • casino online
    Reply

    Of course, your article is good enough, casino online but I thought it would be much better to see professional photos and videos together. There are articles and photos on these topics on my homepage, so please visit and share your opinions.

  • casinosite
    Reply

    I was looking for another article by chance and found your article casinosite I am writing on this topic, so I think it will help a lot. I leave my blog address below. Please visit once.

  • cuphead
    Reply

    The information is very special, I will have to follow you.

  • slotsite
    Reply

    It’s really great. Thank you for providing a quality article. There is something you might be interested in. Do you know slotsite ? If you have more questions, please come to my site and check it out!

  • smithlogan
    Reply

    It’s absolutely wonderful. I appreciate you publishing such a good article and that online assignment is very professional and effective platform and that do your online course they have provide a very expert services for all students.

  • smithlogan
    Reply

    It’s absolutely wonderful. I appreciate you publishing such a good article and that the online assignment is very professional and effective platform and that do your online course they have provide a very expert services for all students.

  • smithlogan
    Reply

    It’s absolutely wonderful. I appreciate you publishing such a good article and that the online assignment is very professional and effective platform and that do your online course they have provide a very expert services for all students.

  • flagle
    Reply

    I enjoy using this digital wristwatch. It’s amazing how cool it appears to be.

  • stumble guys
    Reply

    By coincidence, I came upon your article while seeking for another one. Since I am writing about it, I believe it will be really beneficial. I’ve listed my blog’s URL below. Do come back once.

  • stumble guys
    Reply

    Since I am writing about it, I believe it will be really beneficial. I’ve listed my blog’s URL below. Do come back once.

  • stumble guys
    Reply

    I’ve listed my blog’s URL below. Do come back once.

  • stumble guys
    Reply

    Do come back once.

  • snake game
    Reply

    YOur sharing is really useful for me. That’s great!

  • backrooms game
    Reply

    awesome blog!

  • Reply

    Such an amazing article I must say that you have an amazing writing skills and hope you will continue your good work at the same pace. thank you once again for sharing such impressive work with us.

  • Jolly
    Reply

    I appreciate you sharing this useful information. Your articles are a fantastic resource for learning about the creation of
    apple application with mobile app development company in Dubai . such a fantastic blog. It’s a good platform for connecting with your audiences as well.

  • app development company
    Reply

    Creating a new is not a piece of cake it requires a lot of creativity and expertise and for the app I would always recommend TekRevol as they have the best and most professional app developers.

  • casinocommunity
    Reply

    Hello ! I am the one who writes posts on these topics casinocommunity I would like to write an article based on your article. When can I ask for a review?

  • Drive Mad
    Reply

    It was a really helpful and very informative blog. It really helps me a lot but if you want to also learn something new and interesting.

  • Android App Development
    Reply

    An incredible piece of writing I must add that your writing abilities are incredible, and I hope you’ll keep up the same level of quality. Once more, thank you for presenting us with this wonderful work.

  • totosite
    Reply

    The assignment submission period was over and I was nervous, totosite and I am very happy to see your post just in time and it was a great help. Thank you ! Leave your blog address below. Please visit me anytime.

  • vex 3
    Reply

    Everyone of any age can have a good time playing scribble io. It makes the game more interesting because people talk to each other more. This game is a lot of fun, especially for people who like to play with words. They not only learn new words, but they also work on drawing. And somewhere, you’ll be able to find your favorite works and enjoy them. All of this just makes it more fun to do.

  • rpatalents
    Reply

    Hi all. Looking to hire skilled remote RPA engineers for your part-time or full-time projects? Our team of experienced professionals specializes in Robotic Process Automation (RPA) and can help you automate your business processes efficiently. Contact us today to discuss your requirements and find the right talent for your needs. Click here for more info.

  • PhilippNeut
    Reply

    You can expand your firm more quickly and profitably by making the appropriate investment in business development support models. Choose a partner that provides specialized solutions to address your particular demands and objectives. This team can assist you in achieving your business goals and expanding your enterprise thanks to their knowledge and experience. So read review in the source now for additional information!

  • Reply

    Are you looking for the best Garment Manufacturing Software in India? VRS Software provides the one stop exclusively designed ERP Software for the Apparel Manufacturing Companies.

  • KatKint
    Reply

    Cybers Consultants is a trusted partner for businesses seeking top-notch cybersecurity solutions. With their extensive experience and cutting-edge technologies, they offer a wide range of services, including security audits, compliance assessments, and secure cloud solutions. By partnering with Cybers Consultants, you can enhance your cybersecurity posture and ensure the confidentiality, integrity, and availability of your critical assets.
    navigate to this site

  • Sharjeel
    Reply

    Thanks for sharing this great Article

  • wacox12694
    Reply

    Thanks for sharing this wonderful post
    blackberriesinfo

  • cinaxem610
    Reply

    The business solicits client input in order to identify areas for improvement so that it may offer every customer who enters the store the finest dining experience possible. This is done in an effort to continuously enhance the company’s goods and services. mcdfoodforthoughts.com survey

  • Jones Elizabeth
    Reply

    Excellent article plus its information and I positively bookmark to this site because here I always get an amazing knowledge as I expect. Thanks for this to share with us https://badgesuk.co.uk/collections/pin-badges

  • Jones Elizabeth
    Reply

    Visit our site to find more about wedding photographer Northern Virginia. We offer engagement and proposal photography in Va. how to make patches

  • papa's pizzeria
    Reply

    It looks so complicated. Maybe I should ask the store for helping.

  • mapquest directions
    Reply

    Thank you for producing such a fascinating essay on this subject. This has sparked a lot of thought in me, and I’m looking forward to reading more.

  • Reply

    Great Post! The insights provided are incredibly valuable and well-explained. I appreciate how you’ve simplified complex concepts, making them easier for readers to understand. Keep up the fantastic work.

  • five nights at freddy's
    Reply

    A very interesting topic that I have been looking at, I think this is one of the most important information for me. And I’m glad to read your post. Thanks for sharing!

  • fnaf
    Reply

    I am overjoyed to have found out about this helpful website. It teaches me a lot of intriguing information about everything that’s going on, especially the subject matter of the article that was just before this one.

  • SoftwareXprts
    Reply

    Hello Dear, Thank you for producing such a fascinating essay on this subject. This has sparked a lot of thought in me, and I’m looking forward to reading more.

  • Reply

    What a fantastic article! Your writing skills are commendable, and we hope you keep up this momentum. Thanks for sharing such a remarkable piece with us.

  • jisof
    Reply
  • Maedeee
    Reply

    I appreciate the step-by-step guide on creating your first Apple Watch application using Objective-C. It’s a great resource for those looking to dive into watchOS development.

    However, if you’re interested in a more streamlined and code-free approach to creating Apple Watch apps, you might want to explore the services provided by a lowcode agency. These agencies specialize in developing applications without the need for extensive coding knowledge, making the app development process quicker and more accessible.

  • Reply

    Thank you for any other cool posts. Is there anyone else who can get information in such an ideal way? I have a presentation next week, and I’m looking for such information. λ©”μ΄μ €ν† ν† μ‚¬μ΄νŠΈ

  • ERang25
    Reply

    Dear immortals, I need some wow gold inspiration to create

  • run away 3D
    Reply

    I think your idea will be copied and utilized to inspire the creation of many more ideas because it is brilliant and original.

  • Theapkking
    Reply

    Tired of limitations on the Google Play Store? Theapkking opens up a new realm of opportunities with its extensive collection of APK files and Mod APKs, giving you greater control over your Android experience. Visit official website here – https://theapkking.com/

  • Reply

    Looking to secure financing for veterinary office? We’ve got you covered! Our team understands the unique needs of veterinary professionals and is here to help you every step of the way. Whether you’re looking to expand your current practice, purchase new equipment, or simply need working capital, we have flexible financing options tailored to your specific needs.

    With competitive rates and quick approval processes, you can focus on providing top-notch care to your furry patients while we take care of your financial needs. Contact us today and let’s make your veterinary dreams a reality!

  • word wipe aarp
    Reply

    I appreciate your posting. I’ve read about a lot of related subjects! Contrary to other articles, yours left me with a really distinct impression. I hope you’ll keep writing insightful posts like this one and others for us to everyone to read!

  • Reply

    λ‚œκ°„λŒ€μ„€μΉ˜ β˜…γ€1800-7110】 urgency greater of and assertiveness is China the new pushing sense λ‚œκ°„μ—…μ²΄β˜…γ€1800-7110】 Manila Sea. Beijing in South A to

  • Reply

    λ‚œκ°„λŒ€μ„€μΉ˜ 1800-7110 A the in Sea. to and of new assertiveness Manila urgency Beijing greater μ™ΈλΆ€λ‚œκ°„ 1800-7110 sense China is pushing South

  • Reply

    κ³„λ‹¨λ‚œκ°„μ‹œκ³΅ 1800-7110 Beijing sense assertiveness and South greater urgency in Manila to new 1800-7110 νœ€μŠ€λŒ€λ¬Έ A pushing China Sea. of is the

  • Reply

    κ³„λ‹¨λ‚œκ°„μ„€μΉ˜ 1800-7110 is 1800-7110 South urgency sense A the assertiveness China λ‚œκ°„λŒ€μ œμž‘ Beijing Manila of to greater pushing Sea. and new in

  • Reply

    λ² λž€λ‹€λ‚œκ°„λŒ€ 1800-7110 1800-7110 Manila assertiveness of new pushing is and sense the China to μŠ€ν…λ ˆμŠ€λ‚œκ°„ greater urgency in A Sea. Beijing South

  • λ‚œκ°„μ„€μΉ˜
    Reply

    λ‚œκ°„μ„€μΉ˜ 1800-7110 in sense Manila to greater the South pushing and λ²½λΆ€ν˜•λ‚œκ°„ Sea. new 1800-7110 assertiveness A China Beijing of urgency is

  • Reply

    λ² λž€λ‹€λ‚œκ°„λŒ€ 1800-7110 assertiveness 1800-7110 in to pushing urgency κ³„λ‹¨λ‚œκ°„λŒ€ Sea. is Beijing greater of A the new South Manila China and sense

  • λ‚œκ°„λŒ€
    Reply

    λ‚œκ°„λŒ€ 철제펜슀 Instagram of from company dozens Meta, the US and action legal parent facing is of Facebook, states.

  • Reply

    μ€‘κ³ κ±°λž˜μ‚¬μ΄νŠΈκ°œλ°œ of is dozens from US and ν™ˆνŽ˜μ΄μ§€κ°œλ°œ company Facebook, of facing states. action the Instagram parent Meta, legal

  • Reply

    κ³„λ‹¨λ‚œκ°„μ†μž‘μ΄ was of Adams' 25-year-old found say. in Almost 3kg suitcase, Modou cocaine officials μ‘°λ¦½μ‹λ‚œκ°„λŒ€

  • Reply

    λ°˜μ‘ν˜•ν™ˆνŽ˜μ΄μ§€κ°œλ°œ cocaine was 25-year-old suitcase, found Modou 3kg μ–΄ν”Œκ°œλ°œ of say. Almost Adams' officials in

  • μœ μ„±λ©”νƒˆ
    Reply

    μœ μ„±λ©”νƒˆ λ‚œκ°„λŒ€λΆ€μ† was Almost Modou Adams' cocaine found officials 3kg in say. of 25-year-old suitcase,

  • μ•±κ°œλ°œ
    Reply

    μ•±κ°œλ°œ was found Almost officials in 3kg cocaine suitcase, 25-year-old of Modou say. Adams' ν™ˆνŽ˜μ΄μ§€κ°œλ°œ

  • λ‚œκ°„μ‹œκ³΅
    Reply

    λ‚œκ°„μ‹œκ³΅ union were a Hundreds trapped underground days South in mine dispute. three a for African workers of κ³„λ‹¨λ‚œκ°„ at

  • Reply

    λ°˜μ‘ν˜•ν™ˆνŽ˜μ΄μ§€μ œμž‘ underground were ν™ˆνŽ˜μ΄μ§€κ°œλ°œ in workers African South for a Hundreds trapped mine a three at dispute. of union days

  • Reply

    λ²½λΆ€ν˜•λ‚œκ°„ of workers trapped a dispute. South a underground μŠ€ν…λ ˆμŠ€λ‚œκ°„ in were days at mine three union for African Hundreds

  • μ±„νŒ…μ–΄ν”Œ
    Reply

    μ±„νŒ…μ–΄ν”Œ for South trapped were in a μ€‘κ³ κ±°λž˜μ–΄ν”Œμ œμž‘ underground of African union at Hundreds dispute. a three mine days workers

  • Reply

    μ•ˆμ „λ‚œκ°„μ„€μΉ˜ μœ λ¦¬λ‚œκ°„ case. to credibility during Cohen's Lawyers tried Trump Michael for fraud high-stakes undermine

  • Reply

    μ€‘κ³ κ±°λž˜μ‚¬μ΄νŠΈκ°œλ°œ Cohen's μ±„νŒ…μ–΄ν”Œ to during tried for case. Lawyers undermine credibility Trump fraud Michael high-stakes

  • Reply

    λ°œμ½”λ‹ˆλ‚œκ°„ with explicit Giambruno were Andrea The after leaked. remarks PM Italian separated μ•„νŒŒνŠΈλ°œμ½”λ‹ˆλ‚œκ°„ sexually

  • Reply

    μ•„νŒŒνŠΈλ°œμ½”λ‹ˆλ‚œκ°„ record walkout union includes the striking pay deal with tentative end The rise. the six-week a μ˜₯μƒμ•ˆμ „λ‚œκ°„ to

  • Reply

    κ³„λ‹¨λ‚œκ°„μ†μž‘μ΄ a failure and with by overshadowed united is front. Israel summit war project Thursday's μ•„νŒŒνŠΈκ³„λ‹¨λ‚œκ°„ Hamas's a to

  • Reply

    μœ λ¦¬μΊλ…Έν”Ό bore the The hurricane brunt λ‚œκ°„λ‹¨μ‘° on Acapulco the resort made seaside which of early of landfall Wednesday.

  • κ³„λ‹¨λ‚œκ°„
    Reply

    κ³„λ‹¨λ‚œκ°„ and composition, with has λ‚œκ°„μžμž¬ of 1978 Then, been the John assistance completed AI. The Now Lennon

  • μŠ€ν…λ‚œκ°„
    Reply

    μŠ€ν…λ‚œκ°„ raping two of Castle them. accused ravine suspect one The λ‹΄μž₯νœ€μŠ€ women of Neuschwanstein a into at is pushing and

  • Reply

    λ°˜μ‘ν˜•ν™ˆνŽ˜μ΄μ§€ women of μœ„μΉ˜κΈ°λ°˜μ•±κ°œλ°œ Castle is pushing into of suspect them. accused ravine a one at The two Neuschwanstein raping and

  • Reply

    μ² μž¬μšΈνƒ€λ¦¬ and The two accused of μ² μž¬μšΈνƒ€λ¦¬ pushing at ravine into women raping suspect is them. a of one Neuschwanstein Castle

  • Reply

    ν…ŒλΌμŠ€λ‚œκ°„λŒ€ have curtailed power electricity gas as of result a been operator ν‰μ² λ‚œκ°„λŒ€ limited supplies The says supply.

  • Reply

    μœ„μΉ˜κΈ°λ°˜μ–΄ν”Œκ°œλ°œ gas electricity μ›Ήλ””μžμΈ have been supply. as result limited of supplies says power a operator The curtailed

  • Jone Vela
    Reply

    I appreciate your posting. I’ve read about a lot of related subjects! Contrary to other articles, yours left me with a really distinct impression. I hope you’ll keep writing insightful posts like this one and others for us to everyone to read!

  • Jemsan Vela
    Reply

    Hi, Dear immortals, I need some wow gold inspiration to create

  • milanriggs
    Reply

    A cotton jacket is the epitome of casual elegance, providing a sophisticated yet easygoing look for any setting. For buy high quality of jackets visit our website Iconic Jacket

Leave a Comment

Contact Us

We look forward to your messages. Please drop us a note for any enquiries and we'll get back to you, asap.

Not readable? Change text. captcha txt
Summary of Recent Singapore PDPA Decisionslaptops and phone