解决循环协议声明 [英] Solving circular protocol declarations

查看:87
本文介绍了解决循环协议声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试解决此问题,存在类似的问题,但都不适合我的问题

I am trying to solve this, there are similar questions but none are fit for my issue

我有一个带有@protocol的.h文件. @interface必须具有该@protocol定义.但是@protocol需要类的定义.通函.

I have .h file with a a @protocol. The @interface needs to have that @protocol definition. But the @protocol needs the class's definition. Circular.

如何解决?

@protocol myProtocol

-(void)setupMyClass:(MyClass *)class;

@end

@inteface MyClass

@property (weak, nonatomic) id<myProtocol> delegate;

@end

如果我使用不同的文件,则每个文件都需要导入另一个文件,因此无法解决

If I use different files each needs to import the other, so that doesn't solve it

推荐答案

向前声明该类:

@class MyClass;    // Forward declaration

@protocol MyProtocol
...
@end

@interface MyClass
...
@end

这篇关于解决循环协议声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆