前言
不及跬步無(wú)以至千里祝峻,不積小流無(wú)以成江海。
貴在堅(jiān)持 扎筒,讓關(guān)注我的伙伴們久等了莱找,今天講講在xcode中的另一個(gè)調(diào)試高手chisel,讓你在xcode的編輯中健步如飛嗜桌!
健步如飛.jpg
安裝
- 安裝啟示很簡(jiǎn)單的
brew update
brew install chisel
2奥溺。這里需要注意下:
出現(xiàn)如下情況時(shí):
==> Caveats
Add the following line to ~/.lldbinit to load chisel when Xcode launches:
command script import /usr/local/opt/chisel/libexec/fblldb.py
3.有步驟2,所以在這里 配置環(huán)境:
進(jìn)入終端骨宠,執(zhí)行
touch ~/.lldbinit
vim ~/.lldbinit
用vim編輯器編輯浮定,進(jìn)入文件后相满,加上這樣一句
command script import /usr/local/opt/chisel/libexec/fblldb.py
然后esc,輸入:wq保存并推出桦卒。
重啟Xcode立美,隨便打印一個(gè)斷點(diǎn),進(jìn)入lldb調(diào)試模式方灾,輸入pjson + 你要打印的數(shù)據(jù)建蹄,如果輸入pjson有補(bǔ)全提示的話就代表打印成功了
使用
2.1瀏覽
這個(gè)命令可以打印一個(gè)視圖的層級(jí),如:
(lldb) pviews self.bottomBar
<UIButton: 0x7fed1f59ed00; frame = (127.5 549; 120 40); opaque = NO; layer = <CALayer: 0x600000228620>>
| <UIImageView: 0x7fed1f59f470; frame = (0 0; 120 40); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x60000003aec0>>
2.2 pvc
pvc可以打印一個(gè)viewcontroller的層級(jí)裕偿,而不是查看如:
2.3 可視化
可視化這個(gè)命令比較強(qiáng)大躲撰,它可以使用預(yù)覽應(yīng)用程序打開(kāi)UImageView CGImageRef UIView CALayer如:
visualize uiimageview
2.4 fv&fvc
這兩個(gè)命令是用來(lái)通過(guò)類名搜索當(dāng)前內(nèi)存中存在的視圖和的viewController實(shí)例的命令,支持正則搜索击费。
(lldb) fv bar
2017-08-15 16:50:50.083818+0800 StilliPhone[41689:11858421] [] nw_socket_write_close shutdown(18, SHUT_WR): [57] Socket is not connected
2017-08-15 16:50:50.084305+0800 StilliPhone[41689:11858421] [] nw_endpoint_flow_service_writes [29.1 127.0.0.1:51217 ready socket-flow (satisfied)] Write request has 0 frame count, 0 byte count
2017-08-15 16:50:50.085059+0800 StilliPhone[41689:11858421] [] nw_socket_get_input_frames recvmsg(fd 20, 1024 bytes): [54] Connection reset by peer
2017-08-15 16:50:50.087424+0800 StilliPhone[41689:11833912] [] tcp_connection_write_eof_block_invoke Write close callback received error: [89] Operation canceled
0x7fed1f412b20 UINavigationBar
0x7fed1f50daf0 _UIBarBackground
0x7fed1f71db30 _UINavigationBarBackIndicatorView
0x7fed1f413e50 CYLTabBar
0x7fed1f4140a0 _UIBarBackground
0x7fed1f5134b0 UITabBarButton
0x7fed1f520e30 UITabBarSwappableImageView
0x7fed1f513760 UITabBarButtonLabel
0x7fed1f522a90 UITabBarButton
0x7fed1f418560 UITabBarSwappableImageView
0x7fed1f523910 UITabBarButtonLabel
0x7fed1f6269f0 UITabBarButton
0x7fed1f5250b0 UITabBarSwappableImageView
0x7fed1f626ca0 UITabBarButtonLabel
0x7fed1f5263f0 UITabBarButton
0x7fed1f626f60 UITabBarSwappableImageView
0x7fed1f5266a0 UITabBarButtonLabel
(lldb) fvc bar
0x7fed1f880c00 CYLTabBarController
2.5顯示&隱藏
這兩個(gè)命令用來(lái)顯示和隱藏一個(gè)指定的UIView
(lldb) hide self.bottomBar
(lldb) show self.bottomBar
也可以使用內(nèi)存地址隱藏和現(xiàn)實(shí)視圖拢蛋,比如通過(guò)fv cate找到一個(gè)視圖后使用隱藏隱藏它
(lldb)fv cate
0x7fd5b6e06920 AlbumCategoryView
(lldb) hide 0x7fd5b6e06920
2.6 打印
(lldb) pjson dic
{
"activityname" : "全城尋找高溫下的勞動(dòng)者",
"activityid" : "2806"
}
2.7 標(biāo)記
(lldb) border self.bottomBar
(lldb) unborder self.bottomBar
(lldb) mask self.bottomBar
(lldb) unmask self.bottomBar
2.8 重新渲染 caflush
這個(gè)命令會(huì)重新渲染,即可以重新繪制界面蔫巩, 相當(dāng)于執(zhí)行了 [CATransaction flush] 方法谆棱,要注意如果在動(dòng)畫(huà)過(guò)程中執(zhí)行這個(gè)命令,就直接渲染出動(dòng)畫(huà)結(jié)束的效果圆仔。
例, 其中 $141 即是目標(biāo)_tableView:
(lldb) p _tableView
(UITableView *) $141 = 0x00007fed2000d000
(lldb) e (void)[$141 setBackgroundColor:[UIColor orangeColor]]
(lldb) caflush
2.9 打斷點(diǎn)用 bmessage
這個(gè)命令就是用來(lái)打斷點(diǎn)用的了垃瞧,雖然大家斷點(diǎn)可能都喜歡在圖形界面里面打,但是考慮一種情況:我們想在 [MyViewController viewWillAppear:] 里面打斷點(diǎn)坪郭,但是 MyViewController并沒(méi)有實(shí)現(xiàn) viewWillAppear:方法个从, 以往的作法可能就是在子類中實(shí)現(xiàn)下viewWillAppear:,然后打斷點(diǎn)歪沃,然后rebuild嗦锐。
那么幸好有了 bmessage命令。我們可以不用這樣就可以打這個(gè)效果的斷點(diǎn): (lldb) bmessage -[MyViewController viewWillAppear:] 上面命令會(huì)在其父類的 viewWillAppear: 方法中打斷點(diǎn)沪曙,并添加上了條件:[self isKindOfClass:[MyViewController class]]