1.首先要用到InjectionIII(可在Mac的App Store上下載安裝)
2. 打開(kāi)InjectionIII, Open Project, 選擇你的項(xiàng)目目錄
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);
//改動(dòng)內(nèi)容
#endif
}
// Swift
@objc func injected() {
#if DEBUG
print("I've been injected: \(self)")
//改動(dòng)內(nèi)容
#endif
}
5. 改動(dòng)內(nèi)容后, 直接cmd + S就能看到效果