iOS 热重载

InJection(热重载)

最近一段时间苦恼于UI调试,基本上就是麻木的修改运行Xcode,修改再运行Xcode,苦恼的地方在于项目文件逐渐变大、电脑性能变差造成App编译时间变长,还有就是如果调试的页面层级较深,再跳转到指定页面又是一波操作,很费时间。

今天看到一个介绍热重载的帖子,可以直接看到修改效果,无需重新编译,顿时有种天晴了的感觉,决定尝试并记录使用方法:

原理:

Injection:iOS热重载背后的黑魔法

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.然后在所需要调试的页面添加一下代码

- (void)injected{

NSLog(@"I've been injected: %@",self);// 在此处添加你想要调试的功能// .....

}

使用快捷键command + s快捷键,之后App界面就会做出相应的修改。

当前Injection只能在模拟器上使用。

此功能在调试UI或者API时能提供很大的便利 提高开发效率

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容