Pinch
Pinch

Reputation: 2888

Debugging NSManagedObjectContext

At debugging time, if I have an NSManagedObjectContext, is there a way to look inside to see what objects are in it.

Basically I'm having a save error since there's a CGColor being saved which is not NSCoding compliant. But I have no idea where this CGColor comes from.

Upvotes: 1

Views: 178

Answers (2)

jbbenni
jbbenni

Reputation: 1178

I agree with JR (below) that you should set an exception breakpoint to get a stack trace at the point of failure.

One other thought: although autosaving is convenient, it doesn't always happen at the best time for debugging. You might find it helpful to put in a debugging operation that forces an explicit save when you want to validate your object:

[self.document closeWithCompletionHandler:^(BOOL success) {
     if (!success) NSLog(@“failed to close document %@”, self.document.localizedName);
  }];  

With this, or something like it, you can initiate saving at various points to see when your object becomes corrupted. Do keep in mind that saving is asynchronous.

Upvotes: 2

Jacob Relkin
Jacob Relkin

Reputation: 163318

Well, step back for a second and think about where your error is stemming from.

You're trying to encode a CGColorRef via the NSCoding mechanism. This is obviously not supported and will cause an exception to be thrown. You should add an exception breakpoint in your debugger to introspect where this faulty assignment is being executed. You should then be able to figure out your issue.

If you find that this is somehow unrelated to your problem, then you can indeed introspect the objects which are laying around in your context via the -registeredObjects method.

Upvotes: 2

Related Questions