iosdevuk beyond nslog


# Beyond NSLog()


## Logging

__FILE__ %s
__LINE__ $d
__FUNCTION__ %s
__PRETTY_FUNCTION__ %s

self
NSStringFromSelector(_cmd) - %@
NSStringFromCGRect(rect), etc - logs to %@


#ifdef debug
#define TILOG(...) NSLog(@"%s(%s) %@", _FUNCTION__, __LINE__, [NSString stringWithFormat:__VA_ARGS__])
#else#ifdef DEBUG
# define DLog(fmt, ...) NSLog((@"%s [Line %d] "; fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
# define DLog(...)
#endif
#define TILog(...) do {} while(0)
#end if

## Debugger

Use behaviours window to set debugger to appear when you run the app.
In variables view in debugger (left item in mini toolbar) A symbol is Arguments
L is Local variable
YOU CAN CHANGE VALUES IN THE VARIABLES VIEW AND IT JUST WORKS

Add an exception breakpoint and then inspect to break on Obj-C exceptions
Add symbolic breakpoints to break on particular method calls / variables etc.

Replace log statements with breakpoints with actions set - e.g. log message, make sound, etc.
%B = breakpoint name, %H = hit count
Check 'automatically continue'.
You can also set an ignore count so the actions don't get triggered until X condition.

### gdb command line

s = step

p = print
p variableName

po = print-object
po self

po [self slider]

po [self valueForKey:@"slider]

print (float) [[self slider] value]

print (CGRect) [[self slider] frame]

You can send a message to an object using its address

p (CGRect) [0x4b23... frame]

## Instruments

Use time profiler to see where time is spent in the app.
Tick 'show obj-c only' to see only objective-c calls'.
Black user icon is user-written code.

Use heapshot tool to look for memory issues - set a baseline, see what's been allocated, etc.
Leaks won't find a leak if object isn't actually leaked! - i.e. if pointers still remain. Heapshot will find those straight away.

gdb init lets you save default breakpoints
You can also set breakpoints as user-specific, not project-specific so they're there for everything you do.
Report abuse