不玩LLDB,不知道chisel有多强大。chisel之于LLDB,就像iPhone之于手机,前者几乎给后者重新下了一次定义。如果你还不知道什么是LLDB,请看我上一篇文章《小笨狼与LLDB的故事》。
安装
安装Homebrew
chisel的安装需要使用Homebrew,如果还没有安装Homebrew,可以使用下面的命令安装,如果你已经安装了,可以跳过这一步
1 |
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" |
用Homebrew安装chisel
搞定Homebrew之后,你就可以用他来安装chisel了
1 2 |
brew update brew install chisel |
官网的命令里有一个brew update
,是用来更新Homebrew版本的,如果你是新安装的Homebrew,可以省略掉这条命令
在~/.lldbinit
中添加命令
安装好之后,terminal中会出现这个东西
1 2 3 |
==> Caveats Add the following line to ~/.lldbinit to load chisel when Xcode launches: command script import /usr/local/opt/chisel/libexec/fblldb.py |
意思是需要把这个命令command script import /usr/local/opt/chisel/libexec/fblldb.py
加到~/.lldbinit
文件中
我们将命令其添加进去即可。如果你已经添加过一次了,不需要再次添加
1 2 |
touch ~/.lldbinit echo "command script import /usr/local/opt/chisel/libexec/fblldb.py" >> ~/.lldbinit |
重启一下Xcode,安装完成
更新
如果你想更新chisel,只需要输入更新的命令即可
1 |
brew upgrade chisel |
命令
Autolayout
autolayout中有一种bug叫Ambiguous Layouts,意思是你设置的约束不足以确定view的位置或大小。比如你只设置了X轴的位置,没有设置Y轴的位置
autolayout提供了专门判断和查找这类问题的方法:
1 2 |
hasAmbiguousLayout. Available for both iOS and OS X. Call this method on a misplaced view. It returns YES if the view’s frame is ambiguous. Otherwise, it returns NO. _autolayoutTrace. Available as a private method in iOS. Call this method on a view. It returns a string with diagnostic information about the entire view hierarchy containing that view. Ambiguous views are labeled, and so are views that have translatesAutoresizingMaskIntoConstraints set to YES. |
hasAmbiguousLayout
用于判断是否存在Ambiguous Layouts
_autolayoutTrace
用于查找存在的Ambiguous Layouts
但是即使有查找的方法,真正去做这个事儿也比较费时费力的,这时候chisel给我们提供了更为方便的命令
alamborder
给存在Ambiguous Layouts
的view加上border,方便查找哪些View存在问题
语法:
1 |
Syntax: alamborder [--color=color] [--width=width] |
--color
/-c
: border的颜色,参数为string类型,比如’red’, ‘green’, ‘magenta’等,不设置默认为红色。--width
/-w
: border的宽度,参数为CGFloat类型,不设置默认宽度为2。
e.g: 假设我们写了这么一段代码,可以明显看出,我们没有设置X轴的位置。
1 2 3 4 5 6 |
UIView *subview = [UIView new]; [self.view addSubview:subview]; [subview mas_makeConstraints:^(MASConstraintMaker *make) { make.top.offset(100); make.size.equalTo(@100); 知道什么是LLDB,请看我上一篇文章《小笨狼与LLDB的故事》。
安装安装Homebrewchisel的安装需要使用Homebrew,如果还没有安装Homebrew,可以使用下面的命令安装,如果你已经安装了,可以跳过这一步
用Homebrew安装chisel搞定Homebrew之后,你就可以用他来安装chisel了
官网的命令里有一个 在
|
1 2 3 |
==> Caveats Add the following line to ~/.lldbinit to load chisel when Xcode launches: command script import /usr/local/opt/chisel/libexec/fblldb.py |
意思是需要把这个命令command script import /usr/local/opt/chisel/libexec/fblldb.py
加到~/.lldbinit
文件中
我们将命令其添加进去即可。如果你已经添加过一次了,不需要再次添加
1 2 |
touch ~/.lldbinit echo "command script import /usr/local/opt/chisel/libexec/fblldb.py" >> ~/.lldbinit |
重启一下Xcode,安装完成
更新
如果你想更新chisel,只需要输入更新的命令即可
1 |
brew upgrade chisel |
命令
Autolayout
autolayout中有一种bug叫Ambiguous Layouts,意思是你设置的约束不足以确定view的位置或大小。比如你只设置了X轴的位置,没有设置Y轴的位置
autolayout提供了专门判断和查找这类问题的方法:
1 2 |
hasAmbiguousLayout. Available for both iOS and OS X. Call this method on a misplaced view. It returns YES if the view’s frame is ambiguous. Otherwise, it returns NO. _autolayoutTrace. Available as a private method in iOS. Call this method on a view. It returns a string with diagnostic information about the entire view hierarchy containing that view. Ambiguous views are labeled, and so are views that have translatesAutoresizingMaskIntoConstraints set to YES. |
hasAmbiguousLayout
用于判断是否存在Ambiguous Layouts
_autolayoutTrace
用于查找存在的Ambiguous Layouts
但是即使有查找的方法,真正去做这个事儿也比较费时费力的,这时候chisel给我们提供了更为方便的命令
alamborder
给存在Ambiguous Layouts
的view加上border,方便查找哪些View存在问题
语法:
1 |
Syntax: alamborder [--color=color] [--width=width] |
--color
/-c
: border的颜色,参数为string类型,比如’red’, ‘green’, ‘magenta’等,不设置默认为红色。--width
/-w
: border的宽度,参数为CGFloat类型,不设置默认宽度为2。
e.g: 假设我们写了这么一段代码,可以明显看出,我们没有设置X轴的位置。
1 2 3 4 5 6 |
UIView *subview = [UIView new]; [self.view addSubview:subview]; [subview mas_makeConstraints:^(MASConstraintMaker *make) { make.top.offset(100); make.size.equalTo(@100); 6b2cb142160224-6">} |