xcode 在 Storyboard 文件中与 inferredMetricsTieBreakers 发生合并冲突

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

getting merge conflicts with inferredMetricsTieBreakers in Storyboard file

xcodeinterface-builder

提问by Dan Morrow

Whenever I get a conflict in a storyboard file, I can usually resolve it. However, I have an issue that has now come up twice in two weeks.

每当我在故事板文件中遇到冲突时,我通常可以解决它。但是,我有一个问题,现在在两周内出现了两次。

At the very bottom of my Storyboard file, I see block named "inferredMetricsTieBreakers", with bunch of "segue" tags contained within. It seems that some segue in my local repo is conflicted with another segue in the remote repo. To be safe, I could just "choose both". But since this happened once before, I'm afraid that it will keep happening, and eventually have a long list of these segue references at the end of my storyboard file.

在我的 Storyboard 文件的最底部,我看到名为“inferredMetricsTieBreakers”的块,其中包含一堆“segue”标签。我的本地仓库中的某些 segue 似乎与远程仓库中的另一个 segue 冲突。为了安全起见,我只能“选择两者”。但由于这之前发生过一次,我担心它会继续发生,最终在我的故事板文件末尾有一长串这些 segue 引用。

Just wondering if anyone is that intimately knowledgeable about these tags in the file, or whether I should just blindly continue to just "choose both" and ignore the issue.

只是想知道是否有人对文件中的这些标签非常了解,或者我是否应该盲目地继续“选择两者”并忽略该问题。

Thanks, -Dan.

谢谢,-丹。

采纳答案by Rick Pastoor

Same thing going on here. Got errors in my storyboard file after using your "choose both" method. Found that searching the storyboard for the segue references resulted in one segue that was mentioned inside the inferredMetricsTieBreakerssection. Removing the segue from the list solved my breaking build.

同样的事情发生在这里。使用“选择两者”方法后,我的故事板文件中出现错误。发现在故事板中搜索 segue 引用会导致在该inferredMetricsTieBreakers部分中提到的一个 segue 。从列表中删除 segue 解决了我的破坏性构建。

To try and find out what this inferredMetricsTieBreakersdoes, I tried removing the whole section first. Breaking my build. Next I removed all the items. During the build, Xcode added 2 new and different segues to my list (before the merge I had 3). The application I'm building is working fine.

为了尝试找出它的inferredMetricsTieBreakers作用,我尝试先删除整个部分。打破我的构建。接下来我删除了所有项目。在构建过程中,Xcode 向我的列表中添加了 2 个新的不同的 segue(在合并之前我有 3 个)。我正在构建的应用程序运行良好。

My conclusion: it's safe to remove all the items and perform a clean build. This will keep your storyboard clean.

我的结论是:删除所有项目并执行干净的构建是安全的。这将保持你的故事板干净。

回答by Andrew Hershberger

Each view controller in a storyboard has "Simulated Metrics" which you can see in the attributes inspector:

故事板中的每个视图控制器都有“模拟指标”,您可以在属性检查器中看到:

enter image description here

在此处输入图片说明

Some of these metrics are inferred (thus, inferred metrics).

其中一些指标是推断出来的(因此,推断出的指标)。

As mentioned by @thesystem, if a given view controller is the destination of multiple segues, there could be differences between the simulated metrics of the source view controllers of the segues. To address these differences IB picks a segue to break the tie when resolving the inferred metrics for the destination view controller.

正如@thesystem 所提到的,如果给定的视图控制器是多个 segue 的目的地,则 segue 的源视图控制器的模拟指标之间可能存在差异。为了解决这些差异,IB 在解析目标视图控制器的推断指标时选择了一个 segue 来打破平局。

@rick-pastoor's conclusion that it's safe to remove the entire inferredMetricsTieBreakerssection is correct in that IB can just choose different tie-breaking segues. However, there is no guarantee that the new tie-breakers will lead to the same layout results in IB.*

@rick-pastoor 的结论是,删除整个inferredMetricsTieBreakers部分是安全的,因为 IB 可以选择不同的打破平局的转场。但是,不能保证新的决胜局会在 IB 中产生相同的布局结果。*

For example, I had a situation in which, depending on the tie-breaking segue, a view controller was shown in IB either with or without a status bar. Its view maintained a height of 568pts in both cases, such that the position of the top layout guide kept changing. This snowballed into other undesired (and largely meaningless) changes to the frames of views constrained to the top layout guide.

例如,我遇到过这样一种情况,根据打破平局的转场,在 IB 中显示一个视图控制器,有或没有状态栏。它的视图在两种情况下都保持了 568pts 的高度,因此顶部布局指南的位置不断变化。这导致了对受限于顶部布局指南的视图框架的其他不希望的(并且在很大程度上毫无意义的)更改。

Based on these observations, choosing both the new and old sets of inferred metrics is not advisable. Instead, remove both sets and then open the storyboard in IB to allow the ties to be broken before committing the merge. To avoid undesired frame changes due to a change in tie-breaking segue, pick some value other than "Inferred" for the relevant simulated metrics of the destination view controller. This will ensure that IB generates a consistent layout result.

根据这些观察,不建议同时选择新的和旧的推断指标集。相反,删除两个集合,然后在 IB 中打开故事板以允许在提交合并之前打破联系。为了避免由于打破平局的变化而导致不希望的帧变化,请为目标视图控制器的相关模拟指标选择“推断”以外的其他值。这将确保 IB 生成一致的布局结果。

* The results at runtime should be the same unless there is any logic that relies on the initial layout immediately after the view is unarchived.

* 运行时的结果应该是相同的,除非有任何逻辑在视图未归档后立即依赖于初始布局。

回答by thesystem

It looks like, the tie breakers occur when in the storyboard one view controller is connected from two or more other view controllers via segues and its simulated metrics setting is set to "inferred" but Xcode cannot make sure that inferred means exactly one metrics setting (landscape or portrait) in every case.

看起来,当故事板中的一个视图控制器通过 segues 从两个或多个其他视图控制器连接并且其模拟指标设置设置为“推断”时,就会发生决胜局,但 Xcode 无法确保推断出的指标恰好是一个指标设置(横向或纵向)在任何情况下。

I fixed it by changing all controllers simulated metrics to "inferred" and all metrics are inferred from a controller that has fixed simulated metrics setting "landscape". After that I removed the tie breaker segue ids from the section (but not the section itself).

我通过将所有控制器模拟指标更改为“推断”来修复它,并且所有指标都是从具有固定模拟指标设置“横向”的控制器推断出来的。之后,我从该部分(但不是该部分本身)中删除了决胜局 segue id。

回答by Florin Odagiu

Changed the metrics from Inferred to Freeform (Xcode 8, Swift 3). Solved my problem.

将指标从 Inferred 更改为 Freeform(Xcode 8、Swift 3)。解决了我的问题。