【发布时间】:2009-08-03 18:34:19
【问题描述】:
我有以下代码:
#import <Foundation/Foundation.h>
#import "ServerRequest.h" // works even though this line is included
#import "ServerResponseRecord.h"
@protocol ServerRequestDelegate<NSObject>
-(void)request:(id)request gotResponseRecord:(ServerResponseRecord*)response;
-(void)request:(id)request gotError:(NSError*)error;
@end
它编译并运行良好。但是,如果我将方法声明替换为:
-(void)request:(ServerRequest*)request gotResponseRecord:(ServerResponseRecord*)response;
-(void)request:(ServerRequest*)request gotError:(NSError*)error;
我在 'ServerRequest' 之前收到意外的语法错误“错误:预期的 ')'”。我认为这可能是一个问题的唯一原因是 ServerRequestDelegate.h 和 ServerRequest.h #import 彼此。但是,我不明白为什么代码与带有(id)请求的#import 行一起使用。我也不明白为什么是语法错误。
有人可以提供一个很好的解释吗?
【问题讨论】:
-
stackoverflow.com/questions/10019961/… 有一个明确的导入循环示例以及如何使用
@class避免它。
标签: objective-c xcode gcc compiler-construction import