目的
整合Objective-C與Swift寫的項(xiàng)目同時支持Reveal調(diào)試誉裆,本文推薦的調(diào)試方法不污染項(xiàng)目顿颅,不僅適用于個人開發(fā),也適用于團(tuán)隊開發(fā)足丢。
簡介
有的公司沒有產(chǎn)品原型圖或者沒有給出詳細(xì)界面布局粱腻,需要當(dāng)著產(chǎn)品經(jīng)理修改UI元素,每次修改完了重新運(yùn)行模擬器查看效果是一件非常痛苦的事情斩跌,在此介紹一款工具Reveal绍些,如果沒有了解這款工具,請查看唐巧寫的《iOS界面調(diào)試工具 Reveal》耀鸦。好多文章都給出了Objective-C使用Reveal調(diào)試的方法柬批,在此我不在累贅。本文章出現(xiàn)目的是整合了Objective-C與Swift共同使用同一個腳本袖订,沒有詳細(xì)闡述氮帐,如有不清楚的請移步唐巧文章。
Reveal調(diào)試工具使用步驟:
- 在用戶根目錄創(chuàng)建.lldbinit文件洛姑,打開終端命令輸入以下內(nèi)容
$ cd ~
$ touch .lldbinit
- 使用vim編輯器編輯.lldbinit文件
$ vim .lldbinit
$ i
- 拷貝以下內(nèi)容到.lldbinit文件中
command alias swift_reveal_load_sim expr dlopen("/Applications/Reveal.app/Contents/SharedSupport/iOS-Libraries/libReveal.dylib", 2)
command alias swift_reveal_load_dev expr dlopen(NSBundle.mainBundle().pathForResource("libReveal", ofType: "dylib")!, 2)
command alias swift_reveal_start expr NSNotificationCenter.defaultCenter().postNotificationName("IBARevealRequestStart", object: nil)
command alias swift_reveal_stop expr NSNotificationCenter.defaultCenter().postNotificationName("IBARevealRequestStop", object: nil)
command alias objc_reveal_load_sim expr (void*)dlopen("/Applications/Reveal.app/Contents/SharedSupport/iOS-Libraries/libReveal.dylib", 0x2);
command alias objc_reveal_load_dev expr (void*)dlopen([(NSString*)[(NSBundle*)[NSBundle mainBundle] pathForResource:@"libReveal" ofType:@"dylib"] cStringUsingEncoding:0x4], 0x2);
command alias objc_reveal_start expr (void)[(NSNotificationCenter*)[NSNotificationCenter defaultCenter] postNotificationName:@"IBARevealRequestStart" object:nil];
command alias objc_reveal_stop expr (void)[(NSNotificationCenter*)[NSNotificationCenter defaultCenter] postNotificationName:@"IBARevealRequestStop" object:nil];
- 打斷點(diǎn)與編輯斷點(diǎn)
在AppDelegate類的 application: didFinishLaunchingWithOptions: 方法中上沐,作如下3步操作(如下圖所示):- 點(diǎn)擊該方法左邊的行號區(qū)域,增加一個斷點(diǎn)楞艾,之后右擊該斷點(diǎn)参咙,選擇“Edit Breakpoint”。
- 點(diǎn)擊”Action”項(xiàng)邊右的”Add Action”,
注意:這里和唐巧的文章有點(diǎn)修改
:
swift項(xiàng)目輸入“swift_reveal_load_sim”
OC項(xiàng)目輸入“objc_reveal_load_sim”
- 勾選上Options上的”Automatically continue after evaluating”選項(xiàng)产徊。
- 運(yùn)行程序昂勒,啟動Reveal即可