答案7:
我在Swift、Objective-C和CoreData之间的混合交互方面遇到了类似的问题:在我的项目(用Swift编写)中,我也使用了Core Data的自动生成的Swift类。
但有一次,我需要一个具有公共属性的目标C类(在其标题对应物中定义)来引用核心数据实体。
#import "ProjectName-Swift.h" // this is to import the swift entities into ObjC
@interface myObjCClass : NSObject
@property (nonatomic) MyCoreDataClass*myEntity;
@end
我一更改CoreData模型,XCode就试图重建类,我被指定的循环构建错误挂断了。
在最初的绝望时刻后,由于我的项目中没有任何编译头阶段可以更改顺序,我发现解决方案非常简单:
在myObjCClass.h我删除了共享的Swift头导入语句,并使用@class指令进行了更改:
@class MyCoreDataClass; // tell the compiler I will import the class definition somewhere else
// the rest stays the same
@interface myObjCClass : NSObject
@property (nonatomic) MyCoreDataClass*myEntity;
@end
我将#import "ProjectName-Swift.h"语句移到了myObjCClass.m类定义文件中。
#import "myObjCClass.h"
#import "ProjectName-Swift.h"
@implementation myObjCClass
@end
它没有担心。
网友评论