InJection(熱重載)
最近一段時間苦惱于UI調(diào)試拘悦,基本上就是麻木的修改運行Xcode熏瞄,修改再運行Xcode拍埠,苦惱的地方在于項目文件逐漸變大秸抚、電腦性能變差造成App編譯時間變長豌蟋,還有就是如果調(diào)試的頁面層級較深廊散,再跳轉(zhuǎn)到指定頁面又是一波操作,很費時間梧疲。
今天看到一個介紹熱重載的帖子允睹,可以直接看到修改效果运准,無需重新編譯,頓時有種天晴了的感覺缭受,決定嘗試并記錄使用方法:
原理:
1.先在APPStore搜索下載InJectionIII
2.然后在?application:DidFinishLaunching:?方法中加入如下代碼
Xcode 10.3及以后版本
#ifDEBUG// iOS
[[NSBundle bundleWithPath:@"/Applications/InjectionIII.app/Contents/Resources/iOSInjection.bundle"] load];
// tvOS
?[[NSBundle bundleWithPath:@"/Applications/InjectionIII.app/Contents/Resources/tvOSInjection.bundle"] load];
// macOS
[[NSBundle bundleWithPath:@"/Applications/InjectionIII.app/Contents/Resources/macOSInjection.bundle"] load];#endif
Xcode 10.1
#ifDEBUG
// iOS
[[NSBundle bundleWithPath:@"/Applications/InjectionIII.app/Contents/Resources/iOSInjection10.bundle"] load];
// tvOS
// [[NSBundle bundleWithPath:@"/Applications/InjectionIII.app/Contents/Resources/tvOSInjection10.bundle"] load];
// macOS
// [[NSBundle bundleWithPath:@"/Applications/InjectionIII.app/Contents/Resources/macOSInjection10.bundle"] load];#endif
3.然后在所需要調(diào)試的頁面添加一下代碼
- (void)injected{
NSLog(@"I've been injected: %@",self);// 在此處添加你想要調(diào)試的功能// .....
}
使用快捷鍵command + s快捷鍵胁澳,之后App界面就會做出相應(yīng)的修改。
當(dāng)前Injection只能在模擬器上使用米者。
此功能在調(diào)試UI或者API時能提供很大的便利 提高開發(fā)效率