核心数据:打印实体的内容 [英] Core-Data: Print contents of an entity

查看:131
本文介绍了核心数据:打印实体的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何打印实体的内容,例如



我希望数据具有表格形式,例如,实体数据应该打印如下:



名字|姓氏电话号码|电子邮件| 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆