views:

124

answers:

1

Hi all, How would I print the contents of an entity e.g. customer?

I want the data to be table like, e.g. the entity data should print like so:

First Name | Last Name | Telephone Number | Email | DOB

I also need to apply a search predicate before printing the data, e.g. print members born after 1984

Could anybody tell me how I should do this?

Thanks!

+2  A: 

I found this link which helped me alot using core data: http://iphoneinaction.manning.com/iphone%5Fin%5Faction/2009/09/core-data-part-3-retrieving-data.html

Cast the entity to an array, loop the array and NSLog the data for each result. E.g.:

NSEntityDescription *entity = [NSEntityDescription entityForName:@"news" 
            inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"url=%@",theUrl];
[fetchRequest setPredicate:predicate];

NSError *error;
NSArray *items = [self.managedObjectContext
       executeFetchRequest:fetchRequest error:&error];

for (news *theNews in items) {
 NSLog(@"Title: %@, Date: %@, News: %@", [theNews title], [theNews date], [theNews news]);
}

[fetchRequest release];
Paul Peelen
Thanks! That resource really helped!
Michael