Instant Run or Hot Reloading for Xcode
Asked Answered
M

3

22

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?

Medick answered 1/3, 2017 at 10:22 Comment(5)
Unfortunately that's not (maybe yet) possible.Markson
I hope they add this feature in next versions of xcode ;)Medick
@Markson The Aashish's answer is somehow close to Instant run feature :DMedick
It's kinda but not really ... The initial view controller is what your app starts with, so if in your original flow you pass data from VCA to VCB and then set VCB as the initial view controller, when the app is re-run the data does not get passed to it (because VCA does not get instantiated at all) and you probably can't do much ...Markson
I've found a way to use real Instant Run for iOS ! Please read my answer below to see how.Inflight
I
19

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.

Inflight answered 12/9, 2017 at 13:3 Comment(0)
L
2

You can select the initial - viewController for your project either from the storyboard or programmatically; to the view, which you only need to load at the time for testing.

But, You actually don't need to worry about compiling your code from scratch. This is kind of automate behavior for xCode, as it only compiles your code which you have changed.. You may notice this within your files hierarchy as shown below:-

The 'M' & 'A' at the side of files refers to; 'Modified files' & 'Added files'

The 'M' & 'A' at the side of files refers to; 'Modified files' &

The files without modification; after a build, won't take as much time to build.

Late answered 1/3, 2017 at 11:33 Comment(0)
R
1

if you used that SwiftUI use the next option when your device is connected!!!

and press: cmd + s

enter image description here

Rutherfordium answered 31/1, 2021 at 1:35 Comment(1)
I don't understand what do you mean?Fehr

© 2022 - 2024 — McMap. All rights reserved.