ylliX - Online Advertising Network

Fault data when fetching from CoreData

When you need to quickly display NSArray what you do? Yes, NSLog(@”%@”, myarray), me too. But when you will do this on array fetched from CoreData what will you get? Well, something like:

"<Test: 0x16c950> (entity: Test; id: 0x16c720 <x-coredata://90165BCF-D2DE-4661-9B12-33EF86F0C09F/Test/p1> ; data: <fault>)",
"<Test: 0x16d130> (entity: Test; id: 0x16c730 <x-coredata://90165BCF-D2DE-4661-9B12-33EF86F0C09F/Test/p2> ; data: <fault>)",
"<Test: 0x1684c0> (entity: Test; id: 0x16bfd0 <x-coredata://90165BCF-D2DE-4661-9B12-33EF86F0C09F/Test/p3> ; data: {\n    index = 0;\n    text = Text;\n})",
"<Test: 0x16ab90> (entity: Test; id: 0x16c100 <x-coredata://90165BCF-D2DE-4661-9B12-33EF86F0C09F/Test/p4> ; data: {\n    index = 1;\n    text = Text;\n})"

So what is that? What is surprise – this is not an error, it is normal when you are fetching something, becouse of lazy loading – objects are not fully loaded until you need them. So what can we do? Just a little more work:

for(Item* item in myarray){
   NSLog(@"%@", item.name);
}

This way you will get your array properly displayed, the other way is to [request setReturnsObjectsAsFaults:NO] on your NSFetchRequest but if you will forget to remove it after testing your arrays will always be fully populated which can lead to memory warnings.

Leave a Reply