【发布时间】:2012-05-24 01:53:54
【问题描述】:
我是 iOS 新手。谁能告诉我如何将我的 BO 与 Core Data 映射,以便我可以在我的项目中重用映射。这是我的代码
- (void) saveData
{
CoredataAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSManagedObject *newContact;
newContact = [NSEntityDescription insertNewObjectForEntityForName:@"Person" inManagedObjectContext:context];
[newContact setValue:firstName.text forKey:@"firstName"];
[newContact setValue:lastName.text forKey:@"lastName"];
[newContact setValue:driverLicenceno.text forKey:@"driverLicenceNumber"];
[newContact setValue:state.text forKey:@"state"];
[newContact setValue:phoneNO.text forKey:@"phoneNumber"];
[newContact setValue:injuryStatus.text forKey:@"injuryStatus"];
[newContact setValue:emailAddress.text forKey:@"emailAddress"];
NSLog(@"fName%@",firstName.text);
firstName.text = @"";
NSLog(@"fName%@",firstName.text);
lastName.text = @"";
driverLicenceno.text = @"";
state.text = @"";
phoneNO.text = @"";
injuryStatus.text = @"";
emailAddress.text = @"";
NSError *error;
[context save:&error];
status.text = @"Person saved";
}
除此之外,还有其他方法可以将我的 BO 与 coredata 映射吗?
【问题讨论】:
-
在 Core Data 中映射 BO 是什么意思?你已经有一个数据模型了吗?正如我从您的代码中看到的,您正在使用 Person 实体。那么,你的目标是什么?谢谢。
-
我的目标是将我的 BO 映射到 coredata,这样它将通过映射模型对象自动填充我的 personInfoBO,但无法创建映射模型。这是我关注的链接developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/…
-
使用映射模型是指数据模型吗?
-
告诉我如何在核心数据中应用更新、删除、查找第二个最大值、连接、查看等 sql 查询?