写作方法有困难(新手)

时间:2013-09-10 20:06:22

标签: ios objective-c

在我的课堂上使用Xcode,我们正在为我们的游戏应用添加一个计时器。

这个班级和我自己没有给出书,我所有的其他同学都对如何使用目标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

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

1 个答案:

答案 0 :(得分: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
相关问题