Question

I've researched tons of questions and documents about CoreData returning faults instead of actual values:

Relationship 'whiskers' fault on managed object (0xb7abab0)

This happens when I'm trying to get the count for the number of whiskers, such as:

self.numWhiskersLabel.text = [NSString stringWithFormat:@"%d", cat.whiskers.count];

Even if I try to log the whiskers set directly I still get a fault:

NSLog(@"whiskers: %@", cat.whiskers);

I understand that "Core data will not return full object until there is a need to access the actual value of that object. Each of your returned objects will be a 'fault' until this point." That's great, but there is a need to access the actual value at this point. I need the value right now! So how do I get out of this oxymoron? How can accessing the count of a Set not be considered needing the value?

Was it helpful?

Solution 2

This is an error condition. Something is wrong with that NSManagedObject instance. Either it was deleted before you accessed it or you are trying to touch it from the wrong thread.

Please edit your question and show the code that is accessing that NSManagedObject.

Also, what happens when, in the debugger, you just do a po cat? Do you see the full Cat object or is that giving a fault error as well?

OTHER TIPS

I didn't get any feedback from my comment so I'm just going to assume whiskers is a set of NSManagedObjects

The set wont be loaded initially because internally it's coming from another table in the db. When you access .whiskers.count it still doesn't need to go and get the data yet, because all you're wanting is the number of whiskers in the set.

When you pull a whisker out of the set, then it will be faulted, try doing

NSLog(@"whiskers: %@", [cat.whiskers.anyObject anyProperty]);

That should give you a loaded NSManagedObject.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top