如何打印实体的内容,例如客户?
我希望数据像表格一样,例如实体数据应该像这样打印:
名字|姓氏|电话|邮箱|道布
我还需要在打印数据之前应用搜索谓词,例如打印1984年后出生的成员
有人能告诉我该怎么做吗?
谢谢!
发布于 2009-11-28 00:05:10
我找到了这个链接,它帮助我使用了很多核心数据:http://iphoneinaction.manning.com/iphone_in_action/2009/09/core-data-part-3-retrieving-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], [theNews date], [theNews news]);
}
[fetchRequest release];https://stackoverflow.com/questions/1804773
复制相似问题