Effect:

After saving the code, you can see the effect of the modification in the emulator immediately, avoiding the time-consuming problem of Command+R recompiling. If the APP page hierarchy is too deep, traditional debugging involves stepping step by step into the specified page. With this solution, you can see the results directly. What you see is what you get.


Yesterday, I was stimulated by my colleague’s application of the thermal deployment effect of the Flutter project. After being shown, I thought: There is no reason why he can deploy the flutter with a hybrid while I can use the apple son. So it took me a whole morning, but I finally found this solution to reduce my workload by tons.

Super simple, just 3 steps: 1, a tool 2, select the project directory 3, put a file in the project

No additional configuration is required and no damage is done to the project structure.


Download InjectionIII

InjectionIII is a tool that we need to use. Don’t get bored with this solution just because we have to use a tool. It’s very simple. It’s free, app Store search: InjectionIII, Icon is a needle. Also open source, GitHub link: github.com/johnno1962/…

2. Configure the path

Open the InjectionIII tool, Select Open Project, Select the path where your code is located, and click Select Project Directory to save.

Note: The File Watcher option of InjectionIII should remain selected.

3. (Optional) Import the configuration file.

This step I simply write a configuration file, directly download GitHub import project can be.

If you feel uncomfortable downloading files, you can also handle them yourself:

1. Set the AppDelegate. M open your project, the AppDelegate. M didFinishLaunchingWithOptions method by type to add two lines of 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

2. Set the ViewController

I added method – (void)injected to the ViewController’s modified interface, or I added method – (void)injected to the ViewController class extension.

Method that says refresh action: viewDidLoad or more.

- (void)injected {// Specially modified... // reload view [self loadView]; [self viewDidLoad]; [self viewWillLayoutSubviews]; [self viewWillAppear:NO]; }Copy the code

3. Handle lazy loading and other exceptions

  • Configuration package to modify the view of the refresh, code is not much, but more convenient than your own writing, recommend you download the drag.
  • Because scope of application [self loadView] needs to be called carefully.
  • Lazy loading of the view configuration package is not recognized, need their own manual processing in the VC, example code:
- (void)injected {
    [_tableView removeFromSuperview];
    _tableView = nil;
    [self viewDidLoad];
}
Copy the code

4. Start the project and modify the verification

Run the project in Xcode Command+R and see the Injection Connected message, it indicates that the configuration is successful.

If not, make sure step 2 is right.

On the page that needs to be modified, modify the control UI, and Command+S saves the code and immediately displays the modified information on the emulator.

⚠ ️ note

  • It is better not to have Chinese in the project path. At present, only view and VC save refresh is processed, and some XIB controls are invalid.
  • The Bundle path is related to the Xcode path and the tool path, but is generally not changed.
  • When compiling complex projects, they may crash. Don’t give up, and adjust the method called during its flooding, so that the efficiency can be more than doubled after I injected.
  • Some of my friends replied that I might crash when I registered with RAC + MVVM injected method. INJECTION_BUNDLE_NOTIFICATION could be used to monitor the compilation and update. I will improve the update in the future.

If you have any questions about using the tool, please refer to github’s past experience and leave a comment.

Configuration file git: github.com/ZHSY/Inject…

Git address: github.com/johnno1962/… It can also be downloaded directly from appstore