Xcode 的即时运行或热重载
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42529081/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Instant Run or Hot Reloading for Xcode
提问by Milad Faridnia
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.
我是一名 Android 开发人员,最近开始学习 Swift。Android Studio 中有一个很酷的功能叫做Instant Run,它可以显着减少编码期间增量代码更改的构建和部署时间。
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.
Android Studio 2.0 中引入的Instant Run 是 Run 和 Debug 命令的一种行为,可显着缩短应用更新之间的时间。尽管您的第一个构建可能需要更长的时间才能完成,但 Instant Run 会在不构建新 APK 的情况下将后续更新推送到您的应用程序,因此更改可以更快地被看到。
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).
如果您在 Android Studio 上启用 Instant Run,则无需从头开始构建和运行应用程序,特别是当您在应用程序中间(故事板)处理一些细节视图控制器时。
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?
我很想知道这个功能或类似的东西是否在 XCode 中可用,或者每次我想测试应用程序时我都必须从头开始运行应用程序?
采纳答案by AnthoPak
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.
不久前我发现了这个问题,并得出结论,没有任何方法可以在 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 Xcodeand 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!
但 !我最近发现了一个很棒的库,它允许您将这个很棒的功能带到 iOS。我在这里分享它,因为它对我来说变得必不可少,当我第一次来到这里时,我很想找到它。它被称为Xcode 注入,它采用插件的形式。由于新的 Xcode 限制,安装时间有点长。您必须修补 Xcode 才能在其中运行插件。您可以在自述文件或“问题”中找到所有这些信息。它可能需要长达 30 分钟,但这个插件是一个真正的节省时间!
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!).
安装后,像往常一样使用 Xcode ( CMD + R
)运行您的应用程序。然后,更改控制器中某处的代码。现在,单击CTRL + =
以使用注入插件。您不会在模拟器中看到任何重新加载,但是如果您尝试,您将看到您的代码更改已被执行(几秒钟后!)。
For example you have this line :
例如你有这条线:
self.view.backgroundColor = [UIColor blackColor];
After your app is running with CMD + R
, change the line to :
在您的应用程序运行后CMD + R
,将行更改为:
self.view.backgroundColor = [UIColor whiteColor];
Press CTRL + =
, and enjoy !
按下CTRL + =
,享受!
Hope this helps somebody ! If you have any questions (for installation or other), please ask me in comment.
希望这对某人有帮助!如果您有任何问题(安装或其他),请在评论中问我。
回答by Aashish
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.
您可以选择初始- viewController
;从故事板或编程或者为你的项目 到视图,您只需要在测试时加载它。
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:-
但是,您实际上无需担心从头开始编译代码。这是 xCode 的一种自动化行为,因为它只编译您已更改的代码。您可能会在文件层次结构中注意到这一点,如下所示:-
The 'M' & 'A' at the side of files refers to; 'Modified files' & 'Added files'
文件旁边的“M”和“A”是指;“修改的文件”和“添加的文件”
The files without modification; after a build, won't take as much time to build.
未经修改的文件;构建后,不会花费太多时间来构建。