核心数据表关系和获取请求 [英] Core Data Table Relationship and Fetchrequest

查看:409
本文介绍了核心数据表关系和获取请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用storyboard和核心数据开发一个iPad应用程序。我对核心数据不了解。我有两个表名称A和B.表a有2个字段,名称为datacode和price.In表B有两个字段名称为itemcode和text.Table A已设置限制。

I am developing one iPad application using storyboard and core data.I have no good idea about core data.I have 2 tables names A and B. Table a have 2 fields with names datacode and price.In table B there are two fields with names itemcode and text.Table A have set limit.

表A

数据码价格

p1 10

m1 17

p0 28

m3 20

w4 12

表B

itemcode text

itemcode text

p0 car

p1 bus

m2 pen

m1球

p0 ban

r1书

m3铅笔

n1 tv

w4 radio

tableB中的itemcode中的值是表A中的数据代码+一些其他value.i需要从表B中获取文本值基于项目代码对应于表AI中的数据代码的值,如何基于该标准从B获取文本。

The values in itemcode in tableB is the data code in the table A + some other value.i need to fetch the text values from the tableB based on the itemcodes which values corresponding to the datacode in the table A.I how can i fetch the text from B based on this criteria.

推荐答案

您需要将表A的数据代码用于表B的项目代码,如下所示:

You need to use predicate with your table A's datacode to table B's itemcode, like this:

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

NSEntityDescription *aEntity = [NSEntityDescription entityForName:@"TableA" inManagedObjectContext:moc];
[fetchRequest setEntity:BEntity];

NSArray* fetchResults = [moc executeFetchRequest:fetchRequest error:nil];

您将获得TableA的所有对象。所以如果你与TableB有一对一的关系,你可以直接访问所有的属性,如:

you will get all the objects of TableA. so if you have one - one relationship with TableB, you can directly access the all the attributes like:

TableA *tableAObject = fetchResults[i];
NSString * itemcode = tableAObject.tableBRelation.itemcode

这篇关于核心数据表关系和获取请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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