Notes

Debug

控制台打印视图层级结构

po [<view> recursiveDescription]

Not able to use debug view hierachy

添加 Autolayout Breakpoints

问题

当视图的约束出现错误的时候,控制台在出错约束的最后会提示

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

添加 Autolayout 断点的方法

  1. 按下 ⌘ + 7,转到 Show the Breakpoint navigator
  2. 右下角添加 Symbolic Breakpoint…

  3. 在弹出的对话框中填入配置

    Action 的 Debugger Command

    • 对于 Swift 项目,填入 expr -l objc++ -O -- [[UIWindow keyWindow] _autolayoutTrace]
    • 对于 Objective-C 项目,填入 po [[UIWindow keyWindow] _autolayoutTrace]

  4. 在运行时,当遇到有异常的约束时,会自动停下,并可以实时改变控件的属性,如

     (lldb) expr ((UIView *)0x7f9ea3d43410).backgroundColor = [UIColor redColor]