我的老师给了我这个 main.m,我必须为其编写 .h 和 .m 方法。在我制作的 .m(not main) 文件中,我收到了来自 Xcode 的“不完整实现”警告。我已经为所有被调用的方法制定了方法,所以我无法弄清楚它为什么这么说。这是给我们的代码,我无法修改:
#import <Foundation/Foundation.h>
#import "ChutesAndLadders.h"
int main(int argc, const char * argv[])
{
@autoreleasepool {
ChutesAndLadders *cl = [[ChutesAndLadders alloc]init];
[cl initBoard];
[cl makeChutes:10];
[cl makeLadders:10]
int chutes=0;
int ladders=0;
for(int i=0;i<cl.board.count;i++){
NSString * cell = (NSString *)[cl.board objectAtIndex:i];
int additionalSpaces = (int)[cl addToMove:cell];
if(additionalSpaces>0)
ladders++;
else if (additionalSpaces<0)
chutes++;
}
[cl printBoard];
}
return 0;
}
这是我编码的.h,我相信没问题:
#import <Foundation/Foundation.h>
@interface ChutesAndLadders : NSObject{
@private
NSMutableArray * board;
}
@property (readwrite, retain) NSMutableArray *board;
-(id) initBoard;
-(NSString *)addToMove: (NSString *) cell;
-(void)makeChutes: (int) length;
-(void)makeLadders: (int) length;
-(void)printBoard;
@end
这是我的 .m,这是我在“@implementation ChutesAndLadders”行遇到问题的地方:
#import "ChutesAndLadders.h"
@implementation ChutesAndLadders//incomplete impementation????????????
@synthesize board=_board;
-(void) initBoard{
//self = [super init];
//if (self){
_board = [board initWithCapacity: 100];
//self._board=[[NSMutableArray alloc]initWithCapacity:100];
for(int i =0; i < 100; i++){
[_board addObject:@""];
//}
}
}
-(void)makeChutes: (int) length {
//Make argument number of Chutes randomly across the board.
for(int i = 0; i < length;){
int random = arc4random_uniform(101);
if ([[_board objectAtIndex:random] isEqual:@""]) {
NSString *fString = [NSString stringWithFormat:@"C%d", length];
[_board replaceObjectAtIndex:random withObject:fString];
i++;
}
}
}
-(void)makeLadders: (int) length {
//Make argument number of Ladders randomly across the board.
for(int i = 0; i < length;){
int random = arc4random_uniform(101);
if ([[_board objectAtIndex:random] isEqual:@""]) {
NSString *fString = [NSString stringWithFormat:@"L%d", length];
[_board replaceObjectAtIndex:random withObject:fString];
i++;
}
}
}
-(NSString *)addToMove: (NSString*) cell {
if([[_board objectAtIndex:[cell integerValue]] isEqualToString:@"C10"]){
return (@"-10");
}
if([[_board objectAtIndex:[cell integerValue]] isEqualToString:@"L10"]){
return (@"10");
}
else
return (@"0");
}
-(void) printboard {
//Print the board in rows of 10 so that it looks like a square in console.
for(int i=0; i < (_board.count/10); i++){
for(int j = 0; j < 10; j++){
NSLog(@"|");
NSLog(@"%@", [_board objectAtIndex:(i+j)]);
NSLog(@"|");
}
NSLog(@"\n");
}
}
@end
这是我在 Objective-C 中的第一个任务,一般来说是 Mac,我已经从事了一段时间,主要是研究/学习,我只是看不出我做错了什么。
我还没有运行这个程序,很抱歉你可能会看到任何其他愚蠢的错误,一旦我可以真正让它输出到控制台,我会弄清楚它们,这样我就可以看看它是否在做它应该做的事情。