Wednesday, 7 September 2011

iOSDev UK: Beyond NSLog

Tim Isted, @timisted

NSLog, XCode and gdb

  • useful macros for logging:
    • __FILE__ (full path)
    • __LINE__
    • __FUNCTION__ (and __PRETTY_FUNCTION__)
  • NSStringFromSelector(_cmd) gives you current message
    • Lots of these useful NSString functions, e.g. NSStringFromCGRect
  • use macros in log define
    • non-debug version should be something like: TILog(...) do {} while (0)
  • XCode preferences > Behaviours
    • Run starts — can choose what displays
  • XCode also has a variables view, hidden in the next pane of the debugger
  • add breakpoints for exceptions or non-source code by using little plus button at bottom of breakpoints pane
  • breakpoints have really useful options
    • log to console on hit (with auto hit count)
    • continue automatically
    • only do stuff on conditions
  • gdb commands:
    • s = step = Step In
    • m = Step Over
    • c = Continue
    • p = Print
    • po = Print Object
  • debugging Core Data: use [self valueForKey:@"propertyName"]
  • can use addresses instead of variable names in po
  • can make breakpoints user-specific instead of project-specific

Instruments

  • Time Profiler — great for catching infinite loops!
    • shows you time spent at certain places in call stack
    • tick the “Show Obj-C Only” checkbox
    • look for purple user symbols!
  • Heap Shot tool find leaks
  • quite a few WWDC videos on Instruments

No comments: