Jeff
Jeff

Reputation: 1403

How to show detailed info inside NSLog in CoreData? suggest me a solution

I am using foliowin function to fetch all records in application

-(NSArray*)recordsInTable:(NSString*)tableName andManageObjectContext:(NSManagedObjectContext *)manageObjContext
{
    NSError *error=nil;
    // **** log objects currently in database ****
    // create fetch object, this object fetch's the objects out of the database
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName: tableName inManagedObjectContext:manageObjContext];
    [fetchRequest setEntity:entity];
    NSArray *fetchedObjects = [manageObjContext executeFetchRequest:fetchRequest error:&error];
    return  fetchedObjects;
}

And using the following code to fetch the records

  NSArray *records=[dbAccessObj recordsInTable:@"Details" andManageObjectContext:managedObjectContext];
    NSLog(@"records %@",records);

I am getting a log like this

**records (
    "<Details: 0x76374b0> (entity: Details; id: 0x7636730 <x-coredata://CDEF0797-F141-47A7-902D-9689DCD90B83/Details/p1> ; data: <fault>)",
    "<Details: 0x7637770> (entity: Details; id: 0x7636740 <x-coredata://CDEF0797-F141-47A7-902D-9689DCD90B83/Details/p2> ; data: <fault>)",
    "<Details: 0x7637870> (entity: Details; id: 0x7636750 <x-coredata://CDEF0797-F141-47A7-902D-9689DCD90B83/Details/p3> ; data: <fault>)"
)**

But I want show the log with all details shoiwngin the record shown below.What is the error I made ?

**{
    age = 11;
    fName = "firstName";
    lName = "lastname";
    sId = 4;
})**

Upvotes: 3

Views: 2052

Answers (2)

Camelek
Camelek

Reputation: 21

I think that you could use debugDescription. Just write from debug command line:

po [coreDataObject debugDescription];

It will give you detailed informations.

Upvotes: 1

Martin R
Martin R

Reputation: 539965

There is no error in your code. What you see in the array are "faults". From the Core Data Programming Guide:

Faulting is a mechanism Core Data employs to reduce your application’s memory usage.

... A fault is a placeholder object that represents a managed object that has not yet been fully realized, or a collection object that represents a relationship.

... If at some stage a persistent property of a fault object is accessed, then Core Data automatically retrieves the data for the object and initializes the object.

executeFetchRequest: returns an array of faults (= place holder objects) to save memory. As soon as you retrieve the attribute of an object, the object is fully initialized and all attributes are visible in the debugger.

For debugging purpuses (only), you can force Core Data to fully initialize all objects in the array by

NSArray *allAges = [records valueForKey:@"age"];
NSLog(@"records %@",records);

Upvotes: 2

Related Questions