开发者

require class in protocol

开发者 https://www.devze.com 2023-02-18 11:12 出处:网络
In a method in my protoco开发者_运维百科l I require the class defined in the interface below, how do I solve this;

In a method in my protoco开发者_运维百科l I require the class defined in the interface below, how do I solve this;

@protocol MyDelegate
-(void) somethingFinished:(MyObject*)object anyOtherData:(NSData*)data;
@end

@interface MyObject : NSObject
{
   id<MyDelegate> delegate;
}

// methods

@end

I get the error;

Expected identifier before ':' token


Use forward declaration:

either:

@class MyObject;

@protocol MyDelegate
-(void) somethingFinished:(MyObject*)object anyOtherData:(NSData*)data;
@end

@interface MyObject : NSObject
{
   id<MyDelegate> delegate;
}
@end

or

@protocol MyDelegate;

@interface MyObject : NSObject
{
   id<MyDelegate> delegate;
}
@end

@protocol MyDelegate
-(void) somethingFinished:(MyObject*)object anyOtherData:(NSData*)data;
@end
0

精彩评论

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