更新:最近发现了 腾讯 QMUI 团队开源 iOS UI 调试软件-Lookin;良心之作,真的好用且完全免费。Xcode调试,刚刚滴!!!
官网介绍地址
2018.11.8最新更新:injectionIII使用,Xcode10使用无效,搜了GitHub:
InjectionIII的GitHub,给出了解决办法: 下载InjectionX链接
for Xcode 10:
//Swift:
#if DEBUG
Bundle(path: "/Applications/InjectionIII.app/Contents/Resources/iOSInjection10.bundle")?.load()
//for tvOS:
Bundle(path: "/Applications/InjectionIII.app/Contents/Resources/tvOSInjection10.bundle")?.load()
//Or for macOS:
Bundle(path: "/Applications/InjectionIII.app/Contents/Resources/macOSInjection10.bundle")?.load()
//OC :
// for iOS
[[NSBundle bundleWithPath:@"/Applications/InjectionX.app/Contents/Resources/iOSInjection.bundle"] load];
// for tvOS
[[NSBundle bundleWithPath:@"/Applications/InjectionX.app/Contents/Resources/tvOSInjection.bundle"] load];
// for masOS
[[NSBundle bundleWithPath:@"/Applications/InjectionX.app/Contents/Resources/macOSInjection.bundle"] load];
#endif
#前言:一直羡慕安卓开发:这边改代码,那边瞬间见效果;Xcode还需要编译、项目跑起来,模拟器才能看到效果。有时候XCode编译超慢,一等就是几分钟,实在急死人了。Xcode8以前可以安装插件Injection for Xcode 实现,但是Xcode8以后不能随心所欲的装插件了。现在好啦,不使用插件也可以实现UI即时调试了。
[injection链接](http://johnholdsworth.com/injection.html)
[Mac App Store](https://itunes.apple.com/us/app/injectioniii/id1380446739?ls=1&mt=12)
同时献上网上大牛对这个开发工具的实现原理的分析:《Injection:iOS热重载背后的黑魔法》
[链接地址](https://mp.weixin.qq.com/s/hFnHdOP6pmIwzZck-zXE8g)
使用:
#一、OC:
##1.在我们的项目中- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions方法加入如下代码:
>if DEBUG
// for iOS
[[NSBundle bundleWithPath:@"/Applications/InjectionIII.app/Contents/Resources/iOSInjection.bundle"] load];
// for tvOS
[[NSBundle bundleWithPath:@"/Applications/InjectionIII.app/Contents/Resources/tvOSInjection.bundle"] load];
// for masOS
[[NSBundle bundleWithPath:@"/Applications/InjectionIII.app/Contents/Resources/macOSInjection.bundle"] load];
>endif
注意:if DEBUG 和endif前面少个#(因为加上#就变成黑字体了,也不显示#)
#2.打开Mac APP injectionIII, 点击Mac 桌面的injectionIII 图标-> Open Recent -> 选择你的项目 ,最后再选择FileWatcher(有对号即可);
##3.在任意继承自OC的类中加入如下需要跟新的UI代码,在我们修改了对应文件按下COMMAND + S即可看到UI reload了;
>-(void)injected{
NSLog(@"I've been injected: %@", self);
self.view.backgroundColor = [UIColor goldColor];
}
#二:Swift:
>if DEBUG
Bundle(path: "/Applications/InjectionIII.app/Contents/Resources/iOSInjection.bundle")?.load()
*//for tvOS:*
Bundle(path: "/Applications/InjectionIII.app/Contents/Resources/tvOSInjection.bundle")?.load()
*//Or for macOS:*
Bundle(path: "/Applications/InjectionIII.app/Contents/Resources/macOSInjection.bundle")?.load()
endif
执行快捷键: COMMAND + S
@objc func injected(){
print("I've been injected: \(self)")
}
不过这只是不run XCode情况下,预览UI界面效果,最后要想项目重运行达到效果,还需要把注入的代码写粘贴复制在真实需要改变的地方。
[injectionIIIDemo地址](https://github.com/Dxc123/injectionIIIDemo.git)