What is a InjectionIII

InjectionIII InjectionIII is a tool developed by John Holdsworth that dynamically executes Swift or Objective-C code in a running application, speeding up debugging without having to re-run the application. The tool can be downloaded for free in the Mac AppStore, as shown below:

The author also open-source the software, the source code address

Method of use

1. After downloading the software from Mac AppStore, Open the software and a pinhole icon will appear on the taskbar at the upper right of the computer. Click Open Project or Open Recent, select the root folder of the Project File, and click File Watcher until it is selected.

2. Open the Xcode project, the Appdelegate. M file didFinishLaunchingWithOptions method to add the following code

#if DEBUG
    // 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
Copy the code
#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() #endifCopy the code

3. Add the following methods to your edited ViewController

- (void)injected {

}
Copy the code

Add the code you want to change to this method, run Command + S.

Pay attention to

1. A re-run does not invoke the injected method because it was not actually called

2. It can only be used in emulators