ios 每次击键后 Xcode 都会继续构建故事板

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28476030/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 04:48:35  来源:igfitidea点击:

Xcode keeps building storyboard after each keystroke

iosxcodebuildstoryboard

提问by MrTJ

My Xcode project using a storyboard entered in a very weird state recently: Xcode keeps building the whole project and notably the storyboard after each keypress. I found no reason for this behavior neither in my project diffing all interesting files (storyboard and project) neither a setting in Xcode (maybe I just could not find it?) Needless to say that this "feature" makes working on my project nearly impossible since the CPU is constantly occupying with rebuilding the storyboard when I type new code. Anybody seen this?

我使用故事板的 Xcode 项目最近进入了一种非常奇怪的状态:Xcode 一直在构建整个项目,尤其是在每次按键后构建故事板。我没有发现这种行为的原因,既没有在我的项目中区分所有有趣的文件(故事板和项目)也没有在 Xcode 中的设置(也许我只是找不到它?)不用说,这个“功能”使我的项目几乎不可能工作因为当我输入新代码时,CPU 一直在忙于重建故事板。有人看到这个吗?

回答by MrTJ

It is caused by the IB_DESIGNABLEdefinitions in the source header files. Probably it makes problem only if the header file containing IB_DESIGNABLEis included (even implicitly) to the source file you are currently editing.

它是由IB_DESIGNABLE源头文件中的定义引起的。可能只有当包含的头文件IB_DESIGNABLE包含(甚至隐式)到您当前正在编辑的源文件中时,才会出现问题。

I did not find a definitive solution how to disable IB_DESIGNABLEand thus compiling the storyboard and the source files continuously. I would appreciate an Xcode flag to disable this temporarily. I tried also surrounding the IB_DESIGNABLEwith #ifdefmacros but they are considered even if the #ifdefevaluates to false. Commenting out one by one the IB_DESIGNABLEhelps but it is not a feasible solution with many IB_DESIGNABLEs.

我没有找到一个明确的解决方案如何禁用IB_DESIGNABLE并连续编译故事板和源文件。我希望有一个 Xcode 标志来暂时禁用它。我也试过IB_DESIGNABLE#ifdef宏包围,但即使#ifdef评估为假,它们也会被考虑。一一注释有IB_DESIGNABLE帮助,但它不是一个有很多IB_DESIGNABLEs的可行解决方案。

Update

更新

I finally found a quick way to avoid this annoying behavior. Having the storyboard opened in the active window, disable "Automatically Refresh Views" from the Editor menu. This will stop updating the views in the storyboard editor that use your custom code and thus speed up your development significantly. When you need again the just-in-time compiling to have a visual preview of your custom code, enable this option again (it seems you also have to re-open your storyboard to make it working again).

我终于找到了一种避免这种烦人行为的快速方法。在活动窗口中打开故事板后,从编辑器菜单中禁用“自动刷新视图”。这将停止更新故事板编辑器中使用您的自定义代码的视图,从而显着加快您的开发速度。当您再次需要即时编译以对自定义代码进行可视化预览时,请再次启用此选项(似乎您还必须重新打开故事板以使其再次工作)。

enter image description here

在此处输入图片说明

You may wish to add a key binding to the command, such as command-option-control-A, to easily toggle the behavior on/off. To add a key binding in Xcode, touch command-comma for preferences, choose the Key Bindings tab, use the search bar to find the command, then double-click on the right area to add your desired keystroke.

您可能希望向命令添加键绑定,例如 command-option-control-A,以轻松打开/关闭行为。要在 Xcode 中添加按键绑定,请触摸命令逗号作为首选项,选择按键绑定选项卡,使用搜索栏查找命令,然后双击右侧区域以添加所需的按键。

"Leave it off" approach

“放下它”的方法

Alternately turn "Automatically Refresh Views" off, and never turn it on.

或者关闭“自动刷新视图”,永远不要打开它

Make a convenient keystroke for "Refresh all views", say command-option-shift-R

“刷新所有视图”输入一个方便的按键,比如 command-option-shift-R

enter image description here

在此处输入图片说明

As you work, just touch command-option-shift-R from time to time, or as needed. It's generally only necessary to touch command-option-shift-R as you work on the storyboard.

在您工作时,只需不时或根据需要触摸 command-option-shift-R。通常只需要在您处理情节提要时触摸 command-option-shift-R。

回答by Nick Kirsten

I had this problem and the accepted answer did not work for me.

我遇到了这个问题,接受的答案对我不起作用。

The problem I had was that I always keep the storyboard open in it's own tab within XCode so that I can access it quickly.

我遇到的问题是,我总是在 XCode 中自己的选项卡中保持故事板处于打开状态,以便我可以快速访问它。

The only way I could fix it was to either close that tab or select a different file (like a normal code file) and then close and reopen XCode. Thereafter it was no longer rebuilding on each keystroke.

我可以修复它的唯一方法是关闭该选项卡或选择一个不同的文件(如普通代码文件),然后关闭并重新打开 XCode。此后,它不再在每次击键时重建。

Be warned however if you need to open the storyboard to make changes then this problem can sometimes reappear and I will have to repeat the above process.

但是请注意,如果您需要打开故事板进行更改,那么此问题有时会再次出现,我将不得不重复上述过程。

Can't wait till Apple fixes this as it is very frustrating indeed!

不能等到苹果解决这个问题,因为它确实非常令人沮丧!

(ノ?益?)ノ彡┻━┻

(ノ?益?)ノ彡┻━┻