-3

In my class using Xcode we are adding a timer to our game app.

There was no book given for this class and myself and all my other classmates are up a creek on how to write code using objective c. This is supposedly the intro course to Xcode and App Development, but we are clueless on using this language.

We need to fill in these three methods:

//Clock.m file

#import "Clock.h"

@implementation Clock

int seconds = 1;
int minutes = 60;

- (NSString*) currentTime {
    //return the value of the clock as an NSString in the format of mm:ss
}
- (void) incrementTime {
     //increment the time by one second
}
- (int) totalSeconds;
    //return total seconds in the value of an (int).
@end

Does anyone have any links to tutorials or can help fill in these blanks and explain them in simple terms the syntax of the code?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Maggie S.
  • 1,076
  • 4
  • 20
  • 30
  • This SO answer about NSTimer is pretty good. http://stackoverflow.com/a/1449104/592739 – Pierre Houston Sep 10 '13 at 20:22
  • 1
    Drop whatever it is you're working on and start reading [*Start Developing iOS Apps Today*](https://developer.apple.com/library/ios/referencelibrary/GettingStarted/RoadMapiOS/chapters/Introduction.html#//apple_ref/doc/uid/TP40011343). It links to many other resources and will save you pain and frustration overall. – Carl Veazey Sep 10 '13 at 20:57

1 Answers1

2

You should really ask Google first. Break down your problem into small chunks and go from there.

Hope this helps some while you are learning!

#import "Clock.h"

@implementation Clock

int _time = 0;

- (NSString*) currentTime {
    //return the value of the clock as an NSString in the format of mm:ss
    //You will get minutes with
    int minutes = _time / 60;
     //remaining seconds with
    int seconds = _time % 60;

    NSString * currentTimeString = [NSString stringWithFormat:@"%d:%d", minutes, seconds];

    return currentTimeString;
}
- (void) incrementTime {
    //increment the time by one second
    _time++;
}
- (int) totalSeconds {
//return total seconds in the value of an (int).
    return _time;
}
@end
user-44651
  • 3,924
  • 6
  • 41
  • 87
  • Thank you! This is helpful and makes sense reading it. I was getting frustrated with Google initially, but maybe I just didn't know how to formulate the questions correctly to get the explanation I needed. I will try this code as soon as my next class is over and I'll check if this works. – Maggie S. Sep 10 '13 at 20:49