开发者

Unable to define a protocol with a NSObject as a parameter

For the l开发者_如何学JAVAife of me I cannot figure out what is wrong with this protocol declaration. I get the following errors on the line right after @requred:

Expected * before * Expected ')' before 'MyService'

@protocol MyServiceDelegate

@required
- (void)requestFinished:(MyService *)service;
@end

@interface MyService : NSObject

@property (nonatomic, assign) id <MyServiceDelegate>delegate;
@property (nonatomic, assign) NSURLConnection *connection;

@end


When compiling MyServiceDelegate protocol, the compiler does not know about MyService class. You can use a forward declaration to solve this:

@class MyService;

@protocol MyServiceDelegate
// implementation continues


At the point of the error, the compiler doesn't know about your MyService class - add

@class MyService;

before

@protocol MyServiceDelegate

and it should work perfectly.


You should add @class MyServive; before the protocol. You use it inside the protocol.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜