2011-09-01 5 views
0

다음 코드는 무엇이 문제입니까? Xcode 4는 아래 코드의 주석에 표시된대로 "Question"메시지 앞에 "Question"이있는 두 메서드 선언이 "Question"메시지 전에 컴파일되지 않는다고 말합니다. Question 클래스가 컴파일되고이 코드는 . 이전에 일하고있다 나는 질문을 일부 변경했다하지만,이 컴파일 시간 오류를 파악하는 시도를 철회 여기 컴파일러 오류 - iOS "expected") "before"질문

#import <Foundation/Foundation.h> 
#import "Question.h" 

@interface AppState : NSObject { 

    int chosenAnswer; 
    int correctAnswers; 
    int currentQuestionNumber; 

    // this will contain the hash table of question objects 
    NSMutableDictionary *questionHash; 

} 

@property (nonatomic) int chosenAnswer; 
@property (nonatomic) int correctAnswers; 
@property (nonatomic) int currentQuestionNumber; 
@property (nonatomic, retain) NSDictionary *questionHash; 

- (void)  printQuestions; 
- (void)  printDescription; 
- (void)  addQuestion: (Question *) question; // <==== error 
- (int)   numberOfQuestions; 
- (void)  saveState; 
- (void)  resetState; 
- (Question *) currentQuestion; // <===== error 


@end 

가 Question.h 다음과 같습니다.?

#import <Foundation/Foundation.h> 

#import "AppState.h" 

@interface Question : NSObject { 

    NSString *questionTxt; 
    int   correctAnswer; 
    int   number; 

    // this will contain the hash table of questions_answer objects 
    NSMutableDictionary *answerHash; 

} 


@property (nonatomic, retain) NSString * questionTxt; 
@property (nonatomic) int  correctAnswer; 
@property (nonatomic) int  number; 
@property (nonatomic, retain) NSMutableDictionary *answerHash; 


-(void)       addAnswer: (NSString *) answer; 
- (NSMutableArray *)    answerArray; 
- (void)    printDescription; 
- (void)    printAnswers; 
- (NSString *)   correctAnswerText; 
- (Question *)      currentQuestion; 

@end 
+2

Question.h를 게시 할 수 있습니까? – Maz

+0

예, 질문이 실제로 형식이 아니거나 이상한 것으로 의심됩니다. – jtbandes

답변

4

순환 종속성 AppState 서비스입니다 질문 및 질문 가져 오기에서 AppState를 가져 오는 중입니다.

싸이클을 깨기 위해 앞으로 선언하십시오. 이

@class Question; 

@interface AppState : NSObject { 

    int chosenAnswer; 
    int correctAnswers; 
    int currentQuestionNumber; 

    // this will contain the hash table of question objects 
    NSMutableDictionary *questionHash; 
} 
... 

관련 질문처럼, 당신의 AppState @interface 문 앞에 @class 질문을 사용 @class vs. #import

+0

감사. 그것이 문제였습니다. 나는 @class가 지금 무엇을 사용했는지 더 좋은 아이디어를 가지고있다. –

0

는 질문에 "AppState.h을"# import를 할 때 당신이 순환 종속성을 확인하십시오. #import "AppState.h"및 #import "Question.h"를 구현 부분으로 이동하는 것이 가장 좋습니다. 헤더에서 단지 인터페이스 선언하기 전에

@class Question; 

@class AppState; 

을 둡니다.