Instant Run or Hot Reloading for Xcode

Milad Faridnia picture Milad Faridnia · Mar 1, 2017 · Viewed 12.9k times · Source

I am an Android Developer and recently started learning Swift. There is a cool feature in Android studio called Instant Run, that significantly reduce the build and deploy times for incremental code changes during coding.

Introduced in Android Studio 2.0, Instant Run is a behavior for the Run and Debug commands that significantly reduces the time between updates to your app. Although your first build may take longer to complete, Instant Run pushes subsequent updates to your app without building a new APK, so changes are visible much more quickly.

If you enable Instant Run on Android Studio, There is no need to build and run the app from scratch, specially when you are working on some detail View Controller in the middle of the app (storyboard).

I am curious to know if this feature or sth similar is available in XCode or I must run the app from scratch every time I want to test the app?

Answer

AnthoPak picture AnthoPak · Sep 12, 2017

THERE IS A WAY !

I've found this question a while ago, and conclude that there weren't any way to have a real instant run in iOS.

BUT ! I've recently found an awesome lib that allow you to bring to iOS this awesome feature. I share it here because it became essential for me and I would have loved to found it when I came here the first time. It's called Injection for Xcode and it take the form of a plugin. The installation is a little long because of new Xcode limitations. You will have to patch Xcode to be able to run plugins in it. You can find all these informations in the Read Me or in the "Issues". It can take up to 30 minutes, but this plugin is a real time saver !

Once it is installed, run your app as usual with Xcode (CMD + R). Then, change code somewhere in a controller. Now, click CTRL + = to use the Injection plugin. You won't see any reloading in your simulator, but if you try you will see that your code changes has been taken (in a few seconds!).

For example you have this line :

self.view.backgroundColor = [UIColor blackColor];

After your app is running with CMD + R, change the line to :

self.view.backgroundColor = [UIColor whiteColor];

Press CTRL + =, and enjoy !

Hope this helps somebody ! If you have any questions (for installation or other), please ask me in comment.