我有一个基类@interface BaseMailbox : NSManagedObject
,我有两个孩子。似乎只能通过以下方式创建我的类的对象:
BaseMailbox *mailbox;
mailbox = [NSEntityDescription
insertNewObjectForEntityForName:@"BaseMailbox"
inManagedObjectContext:context];
所以看起来 Core Data 对象不支持多态性?
编辑:
例如,在创建我的邮箱对象之前,我使用了:
account = [[GoogleMailbox alloc]
initWithFullName
当我打电话时account.connect
- 这是与 gmail 参数的连接。
但现在account
没有引用任何子对象,当我调用时account.connect
- 它调用基类方法。
编辑2
BEFORE CORE DATA:
if([_emailAddress.text endsWith:SUFFIX_GOOGLE]){
account = [[GoogleMailbox alloc]
initWithFullName:_fullName.text emailAddress:_emailAddress.text password:_password.text];
}else if([_emailAddress.text endsWith:SUFFIX_YAHOO]){
account = [[YahooMailbox alloc]
initWithFullName:_fullName.text emailAddress:_emailAddress.text password:_password.text];
}else{
…………
BOOL success = [account connect]; // GoogleMailbox or YahooMailbox or ...,depending the account refers to.
核心数据:
BaseMailbox* account = [NSEntityDescription
insertNewObjectForEntityForName:@"MailBox"
inManagedObjectContext:context];
}else{
…………
BOOL success = [account connect]; // BaseMailbox