【问题标题】:Solving circular protocol declarations解决循环协议声明
【发布时间】:2015-10-18 10:53:52
【问题描述】:

我正在尝试解决这个问题,有类似的问题,但没有一个适合我的问题

我有一个带有@protocol 的.h 文件。 @interface 需要具有该 @protocol 定义。但是@protocol 需要类的定义。圆形。

如何解决?

@protocol myProtocol

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

@end

@inteface MyClass

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

@end

如果我使用不同的文件,每个文件都需要导入另一个,所以这并不能解决它

【问题讨论】:

    标签: objective-c protocols circular-reference


    【解决方案1】:

    前向声明类:

    @class MyClass;    // Forward declaration
    
    @protocol MyProtocol
    ...
    @end
    
    @interface MyClass
    ...
    @end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-26
      • 2011-09-20
      相关资源
      最近更新 更多