核心数据:NSLog的输出不显示"场" [英] Core-Data: NSLog output Does Not Show "Fields"

查看:152
本文介绍了核心数据:NSLog的输出不显示"场"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白的NSLog对由NSFetchRequest返回的数组的输出。

I don't understand the output of NSLog for the array returned by a NSFetchRequest.

我读我的数据库,并把该内容在一个阵列,通过阵列循环,然后输出与NSLog的内容。我不明白在日志文件中的输出。低于code:

I'm reading my database and placing the contents in an array, looping through the array and then outputting the contents with NSLog. I don't quite understand the output in the log file. Code below:

-(void)createXMLFeed{
    //Fetch details from the database.
    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Tabrss" inManagedObjectContext:managedObjectContext];
    [request setEntity:entity];
    NSError *error;
    self.stories = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
    //[request release];

    // Count the number of items in the array and display in the log.
    int arrayItemQuantity = [stories count];
    NSLog(@"Array Quantity: %d", arrayItemQuantity);

    // Loop through the array and display the contents.
    int i;
    for (i = 0; i < arrayItemQuantity; i++)
        NSLog (@"Element %i = %@", i, [stories objectAtIndex: i]);

    [stories release]; 

    // Update log file.
    NSLog(@"Database read and XML feed created.");
}

日志文件的内容:

Log file contents:

2010-06-24 10:09:56.918 TAB RSS[998:207] Array Quantity: 15
2010-06-24 10:09:56.919 TAB RSS[998:207] Element 0 = <NSManagedObject: 0x3b3dcb0> (entity: Tabrss; id: 0x3b06a60 <x-coredata://5B703215-A7D8-4E42-834E-A721D78E84BE/Tabrss/p22> ; data: <fault>)
2010-06-24 10:09:56.920 TAB RSS[998:207] Element 1 = <NSManagedObject: 0x3b3e1c0> (entity: Tabrss; id: 0x3b14720 <x-coredata://5B703215-A7D8-4E42-834E-A721D78E84BE/Tabrss/p23> ; data: <fault>)
2010-06-24 10:09:56.920 TAB RSS[998:207] Element 2 = <NSManagedObject: 0x3b3e370> (entity: Tabrss; id: 0x3b1ebd0 <x-coredata://5B703215-A7D8-4E42-834E-A721D78E84BE/Tabrss/p24> ; data: <fault>)
2010-06-24 10:09:56.921 TAB RSS[998:207] Element 3 = <NSManagedObject: 0x3b3e4e0> (entity: Tabrss; id: 0x3b1ecd0 <x-coredata://5B703215-A7D8-4E42-834E-A721D78E84BE/Tabrss/p25> ; data: <fault>)
2010-06-24 10:09:56.921 TAB RSS[998:207] Element 4 = <NSManagedObject: 0x3b3e660> (entity: Tabrss; id: 0x3b3b3f0 <x-coredata://5B703215-A7D8-4E42-834E-A721D78E84BE/Tabrss/p26> ; data: <fault>)
2010-06-24 10:09:56.922 TAB RSS[998:207] Element 5 = <NSManagedObject: 0x3b3e7d0> (entity: Tabrss; id: 0x3b09d20 <x-coredata://5B703215-A7D8-4E42-834E-A721D78E84BE/Tabrss/p27> ; data: <fault>)
2010-06-24 10:09:56.922 TAB RSS[998:207] Element 6 = <NSManagedObject: 0x3b3e940> (entity: Tabrss; id: 0x3b3cf20 <x-coredata://5B703215-A7D8-4E42-834E-A721D78E84BE/Tabrss/p28> ; data: <fault>)
2010-06-24 10:09:56.924 TAB RSS[998:207] Element 7 = <NSManagedObject: 0x3b3eac0> (entity: Tabrss; id: 0x3b3cf30 <x-coredata://5B703215-A7D8-4E42-834E-A721D78E84BE/Tabrss/p29> ; data: <fault>)
2010-06-24 10:09:56.924 TAB RSS[998:207] Element 8 = <NSManagedObject: 0x3b3ec40> (entity: Tabrss; id: 0x3b3cf40 <x-coredata://5B703215-A7D8-4E42-834E-A721D78E84BE/Tabrss/p30> ; data: <fault>)
2010-06-24 10:09:56.925 TAB RSS[998:207] Element 9 = <NSManagedObject: 0x3b3edb0> (entity: Tabrss; id: 0x3b3cf50 <x-coredata://5B703215-A7D8-4E42-834E-A721D78E84BE/Tabrss/p31> ; data: <fault>)
2010-06-24 10:09:56.925 TAB RSS[998:207] Element 10 = <NSManagedObject: 0x3b3ef20> (entity: Tabrss; id: 0x3b3cf60 <x-coredata://5B703215-A7D8-4E42-834E-A721D78E84BE/Tabrss/p32> ; data: <fault>)
2010-06-24 10:09:56.926 TAB RSS[998:207] Element 11 = <NSManagedObject: 0x3b3f090> (entity: Tabrss; id: 0x3b3cf70 <x-coredata://5B703215-A7D8-4E42-834E-A721D78E84BE/Tabrss/p33> ; data: <fault>)
2010-06-24 10:09:56.926 TAB RSS[998:207] Element 12 = <NSManagedObject: 0x3b3f200> (entity: Tabrss; id: 0x3b3cf80 <x-coredata://5B703215-A7D8-4E42-834E-A721D78E84BE/Tabrss/p34> ; data: <fault>)
2010-06-24 10:09:56.927 TAB RSS[998:207] Element 13 = <NSManagedObject: 0x3b3f380> (entity: Tabrss; id: 0x3b3cf90 <x-coredata://5B703215-A7D8-4E42-834E-A721D78E84BE/Tabrss/p35> ; data: <fault>)
2010-06-24 10:09:56.927 TAB RSS[998:207] Element 14 = <NSManagedObject: 0x3b3f500> (entity: Tabrss; id: 0x3b3cfa0 <x-coredata://5B703215-A7D8-4E42-834E-A721D78E84BE/Tabrss/p36> ; data: <fault>)
(gdb) continue
2010-06-24 10:09:57.932 TAB RSS[998:207] Database read and XML feed created.

这是什么意思?:

What does this mean?:

<NSManagedObject: 0x3b3dcb0> (entity: Tabrss; id: 0x3b06a60 <x-coredata://5B703215-A7D8-4E42-834E-A721D78E84BE/Tabrss/p22> ; data: <fault> 

我想实际看到从数据库字段的内容。

I want to actually see the contents of the field from the database.

我有15个记录在我的数据库,并在每个记录12场。从我的基本的了解,它看起来像我的数组从数据库中持有整个记录,而不是单个字段的故事。也许我需要一个二维数组做到这一点,如果是这样,我怎么去这样做?

I have 15 records in my database and 12 fields in each record. From my basic understanding, it looks like my stories array is holding the entire record from the database and not the individual fields. Maybe I need a 2D array to accomplish this, if so, how do I go about doing that?

最后,我想通过数组循环,并为每个字段创建XML标签。但一步一个脚印的时间...

Ultimately I want to loop through the array and create XML tags for each field. But one step at a time...

在预先感谢斯蒂芬

推荐答案

要查看您必须直接引用它们的数组中的对象的各个领域。您使用此,以显示阵列中的对象:

To view the individual fields of the objects in the array you must reference them directly. You are using this to show the objects in the array:

NSLog (@"Element %i = %@", i, [stories objectAtIndex: i]);

的NSLog当你使用%@,这往往是令人费解的或无用的生成每个对象的描述。如果你想看看里面的字段尝试是这样的:

NSLog generates a description of each object when you use %@, which is often convoluted or useless. If you want to see the fields inside try something like this:

NSLog (@"Element %i contains fields: %d - %s - %d",i,[[stories objectAtIndex: i] getIntegerField],[[stories objectAtIndex: i] getStringField],[[stories objectAtIndex: i] getAnotherIntegerField]);

显示的将是各的getter函数的返回值的值对象,你的故事被引用。

The values displayed will be the values returned by the getter functions of each object you are referencing in stories.

这篇关于核心数据:NSLog的输出不显示&QUOT;场&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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