在iOS中使用核心数据映射业务对象 [英] Mapping Business Objects with Core Data in iOS

查看:121
本文介绍了在iOS中使用核心数据映射业务对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iOS新用户。任何人都可以告诉我如何映射我的BO与核心数据,以便我可以在我的项目中重用映射。这是我的代码

I am new in iOS. Can anyone tell about how I can map my BO with Core Data so that I may reuse mapping in my project. Here is my code

- (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除此之外? / p>

Is there any othere way to map my BO with coredata other than this?

推荐答案

Tahir首先你必须创建你已经创建的Coredata db。接下来在coredata模型的Entity面板中选择表。右键单击项目Hirarchy树中的模型。选择新文件,选择coredata和NSManagedObjectSubclass,然后保存它。它为coredata表创建模型类,您可以在方法中使用它。

Tahir first you must create Coredata db which you already create. Next select table in Entity panel in coredata model.Right click model in project hirarchy tree. Select new file , select coredata and NSManagedObjectSubclass and than save it. It create model class for coredata table which you can use in your methods.

此图像显示选择db和表以右键单击并选择NSManagedObjectSubClass

This image show selection of db and table to right click and select NSManagedObjectSubClass

此图像显示第一个coredata比NSManagedObjectSubClass的选择,此后单击下一步它显示给你名字并保存在你的项目。
我希望这将帮助你感谢你!

This image show selection of first coredata than NSManagedObjectSubClass and after this when you click next it show you panal to give name and save this in your project. I hope this will help you thank you!

这篇关于在iOS中使用核心数据映射业务对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆