-3

在我使用 Xcode 的课程中​​,我们正在向我们的游戏应用程序添加一个计时器。

这门课没有书,我和我所有的其他同学都在学习如何使用objective c编写代码。这应该是 Xcode 和 App Development 的入门课程,但我们对使用这种语言一无所知。

我们需要填写这三个方法:

//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

有没有人有任何教程链接或者可以帮助填写这些空白并用简单的术语解释代码的语法?

4

1 回答 1

2

你真的应该先问谷歌。把你的问题分解成小块,然后从那里开始。

希望这对您学习时有所帮助!

#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
于 2013-09-10T20:36:30.903 回答