Core-Data: Print contents of an entity
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 afte开发者_Go百科r 1984
Could anybody tell me how I should do this?
Thanks!
I found this link which helped me alot using core data: http://iphoneinaction.manning.com/iphone_in_action/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];
精彩评论