Basic Timer App

Discussion in 'Mac Programming' started by Haqq, Oct 11, 2010.

  1. Haqq macrumors member

    Sep 5, 2008
    I am pretty new to programming and I was hoping someone can write up a quick tutorial or lesson? on how to create a simple mac app

    It be basically like this

    WORK: -30
    BREAK: -10

    When I push START the timer of 30minutes will go on once complete sound will go off in which the break timer starts. Once the 10 minutes come to a complete within the break timer sounds goes off back to the work timer - thus in a loop.

    Does this seem hard or like a lot of work? I'm not really sure being a super novice.

    Thanks guys.

  2. Hansr macrumors 6502a

    Apr 1, 2007

    You should be able to knock this out relatively quickly. If you know any programming and just need to get a glimpse of Mac specific programming I'd say an hour or two.
  3. xStep macrumors 68000

    Jan 28, 2003
    Less lost in L.A.
    It is an easy enough application to create. You'll need to look into a few Classes and methods.

    In your custom class, you'll need at least a start date, and and perhaps two numbers each for your two different intervals. Oh, and a boolean flag to know which sequence you are counting for. The pros here will know that it can be done with less. ;)

    NSTimer is a class that allows you to repeatedly call a method in an Object via a supplied time interval. You'll create a time, prime it with your work time for the interval and invalidate & release it when work is complete. Then switch to break and do the same. Switching back and forth would allow you to infinitely run your app.

    You'll likely want to use NSDate and the timeIntervalSinceDate: method. Every time you start work or break, you set the NSDate to the current time. As your method gets called from your timer, you compare that date to the current date and evaluate to the now current time. If the difference is greater than the current interval you are using, then it is time to switch intervals and reset the NSDate you are keeping track of.

    For generating speech, look into NSSpeechSynthesizer.

Share This Page