老实说,我不知道这里出了什么问题。这段代码以前工作过,所有相关文件都写得很好,可以自己编译(甚至是各自的.m
文件),但是我.h
的一个 OC 项目中有一个文件,其中 Xcode 不断抛出相同的编译错误。有时每行多次,有时只有一次,但总是在useCommand
变量上。下面是整个受影响.h
文件的屏幕截图和复制/粘贴代码,这是唯一无法编译的文件。当我注释掉对 的每个引用时,程序运行完美useCommand
,但是当我取消注释它们时,再次发生这种情况。我什至创建了一个新项目并将所有代码复制/粘贴到新文件中,但仍然出现此错误。当我移动useCommand
引用新行,Xcode 的错误随之而来。有人知道 Xcode 发生了什么吗?我很确定这不是我的错误,因为我已经四次检查了我的代码以确保一切正常,并且我已经多次清理了目标。
课程
Minecraftia.h
//
// Minecraftia.h
// TextCraft
//
// Created by Supuhstar on 4/3/12.
// Copyright 2012 Blue Husky Programming. All rights reserved.
//
#import <Cocoa/Cocoa.h>
#import "Command.h"
#import "HelpCommand.h"
#import "UseCommand.h"
#import "GetCommand.h"
#import "LookCommand.h"
#import "IO.h"
@interface Minecraftia : NSObject
{
HelpCommand *helpCommand;
UseCommand *useCommand;
GetCommand *getCommand;
LookCommand *lookCommand;
}
-(id)init;
/**
* If none has already been created, creates a static instance of Minecraftia
*
* Returns the same instance of Minecraftia each time
*/
+(Minecraftia *)sharedInstance;
/**
* Turns the given string into a command
* If no matching command is found, nil is returned
*/
-(Command *)toCommand:(NSString *)input;
/**
* The main method of the game, wherein all interactions happen
*/
-(void)play;
/**
* Returns a random message to be used as splash text when the program is started
*/
-(NSString *)getASplash;
/**
* Returns an NSArray of all the available commands
*/
-(NSArray*)getRegisteredCommands;
@property (retain, nonatomic, readonly) HelpCommand *helpCommand;
@property (retain, nonatomic, readonly) UseCommand *useCommand;
@property (retain, nonatomic, readonly) GetCommand *getCommand;
@property (retain, nonatomic, readonly) LookCommand *lookCommand;
@end
帮助命令.h
//
// HelpCommand.h
// TextCraft
//
// Created by Student4 on 4/9/12.
// Copyright 2012 Blue Husky Programming. All rights reserved.
//
#import <Cocoa/Cocoa.h>
#import "Command.h"
#import "Minecraftia.h"
@interface HelpCommand : Command {
}
@end
帮助命令.m
//
// HelpCommand.m
// TextCraft
//
// Created by Student4 on 4/9/12.
// Copyright 2012 Blue Husky Programming. All rights reserved.
//
#import "HelpCommand.h"
@implementation HelpCommand
-(bool)execute:(NSArray *)info
{
NSString *helpString = @"Here are all the available commands:\n";
NSArray *commands = [[Minecraftia sharedInstance] getRegisteredCommands];
for(int i=0, l=[commands count]; i < l; i++)
{
helpString = [NSString stringWithFormat:@"\t> %@", [helpString stringByAppendingString:[[[commands objectAtIndex:i] class] triggerText]]];
}
MyLog([NSString stringWithFormat:@"%@\n\n", helpString]);
return true;
}
+(NSString *)triggerText
{
static NSString *triggerText = @"HELP";
return triggerText;
}
@end