核心数据:打印实体的内容 [英] Core-Data: Print contents of an entity
问题描述
如何打印实体的内容,例如
我希望数据具有表格形式,例如,实体数据应该打印如下:
名字|姓氏电话号码|电子邮件| DOB
我还需要在打印数据之前应用搜索谓词。
谢谢!
>我发现这个链接帮助我使用核心数据:
http://iphoneinaction.manning.com/iphone_in_action/2009/09/core-data- part-3-retrieval-data.html
将实体投射到数组,循环数组,NSLog为每个结果的数据。例如:
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],[the News date] ,[新闻新闻]);
}
[fetchRequest release];
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!
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];
这篇关于核心数据:打印实体的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!