代码之家  ›  专栏  ›  技术社区  ›  jhoff

如果链接框架包含私有头,Xcode项目会抱怨缺少文件。

  •  1
  • jhoff  · 技术社区  · 14 年前

    我的问题是:

    • 我的框架包含公共和私有头-公共头导入私有头 在框架中
    • 与此框架链接的应用程序导入公共头文件

    现在,当我编译它时,Xcode抱怨缺少文件(通过框架公共头间接导入的私有头)。我在某个地方读过 stackoverflow 我应该这样做:

    “在公共头文件中,使用@class包含其他接口,并在实现文件(.m)中使用import。”

    我觉得这个解决方案很不满意——你也必须将它用于循环依赖。有没有更好的方法来保密我的邮件头?

    1 回复  |  直到 14 年前
        1
  •  1
  •   Andrew Hooke    14 年前

    要了解循环引用,请使用头文件中的@class指令和源文件中的import。

    在OtherClass.h中:

    @class MyClass;
    @interface OtherClass
    {
        MyClass *myInstance;
    }
    @end
    

    在OtherClass.m中:

    #import "OtherClass.h"
    #import "MyClass.h"
    @implement OtherClass
    @end
    

    在myclass.h中:

    @class OtherClass;
    @interface MyClass
    {
        OtherClass *otherInstance;
    }
    @end
    

    在myclass.m中:

    #import "MyClass.h"
    #import "OtherClass.h"
    @implement MyClass
    @end