0

An incredible tip for debugging constraint issues print the constraint`s id in lldb

But what should I do to let the lldb print my category`s description?

@interface NSLayoutConstraint (Description)

@end

@implementation NSLayoutConstraint (Description)

-(NSString *)description {
    return [NSString stringWithFormat:@"id: %@, constant: %f", self.identifier, self.constant];
}

@end

Help is really appreciated :)

Community
  • 1
  • 1
Evoque
  • 11
  • 8

1 Answers1

0

You can use the description method in two ways. One, if in the code in your app somewhere you do:

NSLog(@"My Object: %@", my_object);

then %@ specifier will print the NSString returned by the "description" method of your object.

Another way is in the debugger:

lldb (and gdb before it) has a command called po - which is short for print-object. It's job is to take some expression, evaluate it, interpret the result (in the case of ObjC) as an NSObject and send that object the description method.

So in the debugger you can just call

(lldb) po object

and get your printout.

One detail, though: po actually first checks if the object responds to debugDescription and it will call that in preference to description. So if you are extending an object that implements debugDescription (some Kit objects do this) then po will show you the result of the debugDescription method, not your description.

Jim Ingham
  • 25,260
  • 2
  • 55
  • 63