【发布时间】:2015-05-15 15:34:08
【问题描述】:
大家好,
我在使用 Realm 时遇到了一个小问题,我有一个类“Contact”和一个子类“Person”,定义为:
人.h
#import <Realm/Realm.h>
#import "Contact.h"
RLM_ARRAY_TYPE(Person)
@interface Person : Contact
@property NSString * nickName;
@end
我有一个名为“Address”的实体,它具有“Contact”属性(地址只能与一个联系人相关)。
地址.h
#import <Realm/Realm.h>
@class Contact;
RLM_ARRAY_TYPE(Address)
@interface Address : RLMObject
@property NSString * city;
@property NSString * country;
@property RLMContact *contact;
@end
问题是:当我尝试将“Person”对象设置为“Address”的联系人属性时,出现此错误:
[address setContact:person];
'Can't set object of type 'Person' to property of type 'Contact'
我尝试投射它,但仍然是同样的问题:
[address setContact:(Contact *)person];
'Can't set object of type 'Person' to property of type 'Contact'
我什至在我的 Address.h 上定义了 Person 类之后尝试过,但仍然是同样的问题:
地址.h
#import <Realm/Realm.h>
@class Contact;
@class Person;
RLM_ARRAY_TYPE(Address)
@interface Address : RLMObject
@property NSString * city;
@property NSString * country;
@property RLMContact *contact;
@end
有人有想法吗?
提前谢谢各位。
【问题讨论】:
标签: realm