iOS InjectionIII实现热加载

1.首先要用到InjectionIII(可在Mac的App Store上下载安装)
2. 打开InjectionIII, Open Project, 选择你的项目目录
3.在AppDelegate的DidFinishLaunchingWithOptions配置InjectionIII的路径
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
#ifdef DEBUG

    //InjectionIII 注入
    [[NSBundle bundleWithPath:@"/Applications/InjectionIII.app/Contents/Resources/iOSInjection.bundle"] load];

#else

#endif
    return YES;
}
4.在你需要的地方添加injected方法
// Objective-C:
- (void)injected {
    #ifdef DEBUG
        NSLog(@"I've been injected: %@", self);
        //改动内容
    #endif    
}
// Swift
@objc func injected() { 
    #if DEBUG 
        print("I've been injected: \(self)")
        //改动内容
    #endif 
}
5. 改动内容后, 直接cmd + S就能看到效果

你可能感兴趣的:(iOS InjectionIII实现热加载)