Reputation: 195
My teacher has given me this main.m that I must code the .h and .m methods for. In my .m(not main) file I made I am getting an "Incomplete implementation" warning from Xcode. I have made methods for all that were called so I can't figure out why it is saying that. Here is the code given to us that I cannot modify:
#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;
}
Here is the .h that I coded, I believe it is OK:
#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
Here is my .m which is where I'm having the problem at the "@implementation ChutesAndLadders" line:
#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
This is my first assignment in Objective-C, Macs in general for that matter, and I've been at it for some time, mostly research/studing and I just can't see what I'm doing wrong.
I have not ran this program so sorry for any other stupid errors you may see, I will figure them out once I can actually get it to output to the console so I can see if it is doing what it is suppose to.
Upvotes: 1
Views: 1172
Reputation: 26917
The initBoard
method has different return type in m
file. Also, Objective-C is case sensitive. printBoard
and printboard
are not equal for obj-c compiler.
BTW. You should use init...
name only for constructors. See Naming Methods doc from Apple.
Upvotes: 2
Reputation: 1081
Open the Issue navigator via the triangle/exclamation mark button at upper-left:
If you expand your "Incomplete implementation" Semantic Issue with the little triangle at left, you can see the details of XCode's complaint.
Upvotes: 5
Reputation: 35141
In your .h file, there's a method named -(void)printBoard;
But in your .m file, its name is -(void)printboard
. Objective-C is case intensive.
And also, the -(id)initBoard;
and -(void)initBoard
.
Upvotes: 1
Reputation: 1636
You have defined addToMove
and printBoard
in the header file, but they are missing in the .m file. That is the reason for the warning.
Upvotes: 0