1

我的老师给了我这个 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,我已经从事了一段时间,主要是研究/学习,我只是看不出我做错了什么。

我还没有运行这个程序,很抱歉你可能会看到任何其他愚蠢的错误,一旦我可以真正让它输出到控制台,我会弄清楚它们,这样我就可以看看它是否在做它应该做的事情。

4

4 回答 4

5

通过左上角的三角形/感叹号按钮打开问题导航器:

在此处输入图像描述

如果你用左边的小三角形扩展你的“不完整的实现”语义问题,你可以看到 XCode 投诉的细节。

于 2013-02-20T11:40:25.043 回答
2

该方法在文件initBoard中具有不同的返回类型。m此外,Objective-C 区分大小写。printBoard并且printboard对于 obj-c 编译器不相等。顺便提一句。您应该init...只对构造函数使用名称。请参阅Apple 的命名方法文档。

于 2013-02-20T11:40:49.160 回答
1

在您的 .h 文件中,有一个名为-(void)printBoard;But 在您的 .m 文件中的方法,它的名称是-(void)printboard. Objective-C 是案例密集型的。

而且,-(id)initBoard;-(void)initBoard

于 2013-02-20T11:39:48.030 回答
0

您已在头文件中定义addToMoveprintBoard,但在 .m 文件中缺少它们。这就是警告的原因。

于 2013-02-20T11:35:27.013 回答