Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

Forum Contest: iOS Stopwatch App

Edit: This forum contest has ended. See this week's contest:Build a Blog in Ruby on Rails

Hi everybody,

It's time for a new Treehouse Forum contest! First, watch this video to learn more:

After you've watched the video, please read the details below carefully. I'm looking forward to your entries!

How to Enter: Create your iOS Stopwatch app and either upload your code to Github or provide a zipped version of your project via Dropbox or a similar service.

Due Date: All entries must be submitted by July 20th at 11:45pm ET. Here's a timezone chart so you can see what time that is for your locale.

Prize: The entries will be judged by Treehouse teachers based on both design and code. One winner will receive a free month of Treehouse Gold on us! :) We'll announce the winner on July 21st and reveal the next contest.

Amit Bijlani I can't wait to hear your feedback!

I am a huge fan of simplicity and clarity. So that is the route that I took with my Stopwatch concept.

I welcome your thoughts and feedback on the concept.

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

Hi everyone,

I'm very impressed with the quality of all the entries. Some of you really went out there with innovative UI. It's always difficult to pick a winner, because you all did great and these would make for some awesome portfolio additions. I would encourage you to add it to your Github account.

This week's winner is Charlie Hield! Congrats, Charlie! his entry was great all around. The user interface was unique with a nice animation that used Facebook's latest POP framework.

28 Answers

The due date is in the past, shouldn't it be Juli 20th?

Tnhx! Here is an update timezone chart

Oh man, Amit, I still haven't even finished the Crystal Ball app yet!

Me neither. ^^

I've been waiting for an iOS forum contest for a while now!! so excited :)

Would we past the link to our code in the forums?

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

Yes that's exactly what you would do.

Can we write it in Swift? This seems like the perfect little app for Swift practice.

Overachiever. :P

Who would I share it with on dropbox?

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

Just share the link here in the forum

What kind of methods would we be using to create a stopwatch app. I got all my UI pictures and backgrounds ready, but don't know where to start with the coding. Would NSTimer work, or is something else more appropriate for this?

I think you have to use NSDate... how? I have no idea.

Never heard of NSDate, I guess its time to head over to the apple docs.

Does this help?

"NSDate is a model class. It doesn't fire or do anything except represent a certain date and time. You will have to use both (NSTimer and NSDate) for you stopwatch. When you start the watch save the current date in an NSDate instance and start an NSTimer with a 1 sec interval (or more if you want to display milliseconds). And every time the timer fires, you calculate the difference between the current date and the saved date and show it to the user."

Thanks a lot!

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

NSTimer would work well for this app. Apple has a good Introduction to Timers. The documentation covers the various timers available and how you can use them.

Curiously, are you allowed to use CocoaPods?

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Using CocoaPods generally only helps. :-D Link for those who haven't used it: http://teamtreehouse.com/library/ios-tools

Im having trouble with adding a laps feature to my app. My app looks awesome and works amazing, but it needs that one feature. Can anybody help me out here?

My guess is to have a button that copies the value of the text from your stopwatch label. Every time the user presses the button, they get the value from the time that the button was pressed.

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

I'm excited to see what everyone comes up with. We have three more days to go in this contest.

Adding the final touches to mine Amit Bijlani ! :)

Gah! I know this is a competition but can someone look at my algorithm? I'm going nuts trying to figure out what's wrong. My numbers are compounding when I try to implement the ability to pause. If the first run is 3 seconds and the second run is 2 seconds it shows my total time as 8 seconds. I can't get it to add just the last element of the time array to the previous total. I think my brain is just exhausted.

        endTime = Timer().stopTimer()
        var nextInterval = Timer().calculateInterval(startTime, end: endTime)
        intervals.append(nextInterval)
        println("\(intervals)")
        for var i=0; i < intervals.count; ++i{
            totalTime = totalTime + NSArray(array: intervals).lastObject.doubleValue
        }

I've also tried it with a for-in loop

maybe you should add just the last element in the array.

EDIT: actually i see that you're doing that already. maybe you should set your totalTime to 0 before you implement it in the loop.

I did that in a part that I didn't show. I think it has to do with the for loop but I don't know what I could be doing wrong.

Turns out I don't need the loop at all. I attempted to start with a different method than what I ended with in the loop that wouldn't have worked with out the loop. As I was laying in bed it hit me that if the loop is doubling everything but adding the last number correctly, removing it from the loop should keep it from compounding. WIN. It's all gravy from here!

Here is the link to my completed Stopwatch App!

Additionally, In the file I've also included my design intentions.

Download from Dropbox -https://www.dropbox.com/s/tlqxb8qsjosbm0j/Simple%20Stopwatch%20iOS%20App.zip

Good luck everyone! :)

Hey guys, I really need some help on adding laps to my project. This is what i have, but I want it to save the elapsed time, instead of just projecting what my time label say when you push the button. Also, how can put this in a tableview, not a label?

- (IBAction)lapButtonPressed:(id)sender
{
    self.lapLabel.text = self.timeLabel.text;
}

Maybe you could try adding the elapsed time to an array of elapsed times. Then you could reference that array of times in your tableview. Presumably you would need to use a UITableview instead of UITableViewController, unless your having the elapsed times presented in a different view.

I Included a UITableView in my app to display an array of backgrounds available for the users selection. You can look at mine if your understand it or look here: https://developer.apple.com/library/ios/documentation/uikit/reference/UITableView_Class/Reference/Reference.html

Here's an article on collection types

I'm still a beginner at ios programming, so how would using an array find the elapsed time between the last time the user pressed the lap button?

I just tried it in xCode. I'm getting an error. It doesn't like having a double in an array. I'm clueless sorry!

Here is stopwatch app. Looking forward to see everyone else's :)

https://www.dropbox.com/s/i3idobzo05ipghr/StopWatchImproved.zip

Here is my stopwatch app, very simple one :)

https://www.dropbox.com/s/m2577yomqy2i2ni/StopWatch.zip

Ok guys my app is ALMOST done , except for the laps feature. I don't want to turn it in without it so could anybody offer any last bits of wisdom for me.

Have a look at my app. Laps is working like a charm. I don't really like my own solution though, but I started yesterday. It should at the very least point you in the right direction

Ok I will check it out

I saved the string being displayed and passed it to a table view controller

Finally finished my stopwatch. Enjoy!

Here's my stopwatch app https://github.com/tomdiggle/Stopwatch.

Here's my submission.

Congrats Charlie!

Congrats Charlie

Thanks everyone! Honestly, didn't expect to win, there were a lot of awesome submissions.

My stopwatch is finally done!!!! Here is the link! https://www.dropbox.com/sh/xv5w8h0fe4iadc3/AAAo5LyJ44GZLaDTgSWP3_wha

Tried this in Swift, here is the link - https://github.com/rshankras/THDemoStopWatch

Here's mine, using UIKitDynamics Link To DynamicTime

When will the next forum contest be?

Just out of curiosity, is there going to be another iOS forum contest in the near future?

Hey everyone. I thought that maybe you can help me. When I download the winners Code to look at it it says the link is broken. I think i need to download something else but I'm honestly not sure. I will copy and paste it so you guys can see it.

ld: library not found for -lPods clang: error: linker command failed with exit code 1 (use -v to see invocation)

If someone could help me that would be really awesome!

Did you download this zip file? Then you'll want to open the Stopwatch.xcworkspace file in Xcode.

Awesome! Thank you Charlie.. wow you did a great job on this! Have you been coding before Treehouse?

Thanks! Glad you got it to work. Yes, I've been doing it for years. Joined treehouse to learn iOS and have done some other things along the way.