views:

32

answers:

1

Hi,

I am using Core Data to develop an application, and I have used a 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 :)

A: 

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."

Adam Eberbach
Thank you very much :)
Martyn