在WebServiceAPI.h中,我在下面的代码中提到过,我声明了一个带有所需metod的协议 - (void)apiFinished:(WebServiceAPI *)api。编译代码时,我得到这个错误:WebServiceAPI.h:13:错误:预期')'在'WebServiceAPI'之前(第13行是声明协议方法的地方)。我在哪里做错了?
#import <Foundation/Foundation.h>
@protocol WebServiceAPIDelegate
@required
-(void) apiFinished:(WebServiceAPI *)api;
@end
@interface WebServiceAPI : NSObject{
NSString *address;
NSMutableData *dataWebService;
}
@property (nonatomic, assign) id <WebServiceAPIDelegate>delegate;
@property(nonatomic, retain) NSString *address;
@property(nonatomic, retain) NSMutableData *dataWebService;
@end
答案 0 :(得分:3)
问题是 WebServiceAPIDelegate
在定义时不知道类 WebServiceAPI
。在创建 WebServiceAPIDelegate @protocol 声明之前添加 @class
指令。
// Add the following line to let the compiler stop worrying about
// the existance of class WebServiceAPI
@class WebServiceAPI;
@protocol WebServiceAPIDelegate
@required
-(void) apiFinished:(WebServiceAPI *)api;
@end