Hello,
I don't understand the output of NSLog for the array returned by a NSFetchRequest.
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.
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?
Ultimately I want to loop through the array and create XML tags for each field. But one step at a time...
Thanks in advance, Stephen