开发者

How To Extract Information from NSArray Generated from Core Data NSPredicate?

I am using Core Data to develop an application, and I have used a 开发者_JAVA技巧NSPredicate to 'query' an entity which returns an NSArray of results, as is standard.

The NSArray contains objects of 'EntityA' which itself contains attributes 'AttributeA' and 'AttributeB'.

My question is, how can I extract information from this array?

Furthermore, how would I put items from this array into a UITableView (for example, 'Attribute A')?

Any help would be greatly appreciated :)


In creating your Core Data model you will have gone through the process of generating the Managed Object Class header files (select .xcdatamodel file, right click, Add Files etc...) Once this is done you import them into the files where you will use those objects. Then treat the objects just like any other kind of object:

EntityA* entityA = [returnedArray objectAtIndex:0];
entityA.AttributeA = something;
entityA.AttributeB = something;

When you define relationships in the model you will get either object references (1:1) or NSSet pointers to access (1:many). A small shift in thinking to get your head around it but once you have worked your way through an example or two it's easy.

In UITableView terms, same way you deal with any other data in an array. Or, read up about NSFetchedResultsController: "This class is intended to efficiently manage the results returned from a Core Data fetch request to provide data for a UITableView object."

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜