【发布时间】:2015-10-02 17:51:31
【问题描述】:
我有两个实体,并且刚刚在它们之间创建了 1:1 的关系。实体有子类,但此时它们中有很多代码,所以我不想使用 Xcode 自动生成新的 NSManagedObject 子类。
相反,我认为我可以只引用每个属性中的关系。我这样做了,它似乎工作了一段时间,但现在它抛出了神秘的错误,我似乎无法摆脱它们。我已经导入了每一个的倒数,但它没有帮助。谁能推荐我应该做什么?非常感谢。
Subclassed NSManagedObjects (simplified)
//Items.h
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#import "Notes.h"
@interface Items : NSManagedObject
@property (nonatomic, retain) NSNumber *iid;
@property (nonatomic, retain) NSString *item;
//this is relationship
@property (nonatomic, retain) Notes *note;
//above throws error Unkown Type Name 'Notes'
@end
//Notes.h
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#import "Items.h"
@interface Notes : NSManagedObject
@property (nonatomic, retain) NSNumber * nid;
@property (nonatomic, retain) NSString * note;
//this is relationship
@property (nonatomic, retain) Items *item;
//above throws error Unkown Type Name 'Item'
@end
这类似于关系
【问题讨论】:
-
为什么要使用保留而不使用 ARC(如果使用,请使用非原子,强)?
-
@Ron 我假设他正在使用保留,因为 Xcode 生成的类仍然使用保留来实现向后兼容性。
-
谢谢,我尝试了两种方式,因为另一个提到 strong 但会使用strong的配置出错。
标签: ios objective-c relationship nsmanagedobject