Why does git add&remove the Storyboard <classes> section repeatedly?
Asked Answered
O

2

19

When saving the storyboard and committing the changes to git, the chances are good that the whole <classes> section will be removed from or added to source control (git). I am using git on the command line, not the XCode integrated UI.

First it looks like this:

+    <classes>
+        <class className="CPTGraphHostingView" superclassName="UIView">
+            <source key="sourceIdentifier" type="project" relativePath="./Classes/CPTGraphHostingView.h"/>
+        </class>
...
+    </classes>

And in the next commit it looks like that:

-    <classes>
-        <class className="CPTGraphHostingView" superclassName="UIView">
-            <source key="sourceIdentifier" type="project" relativePath="./Classes/CPTGraphHostingView.h"/>
-        </class>
...
-    </classes>

Why is that, and, more importantly: how can I stop that?

Ordway answered 25/4, 2012 at 10:21 Comment(7)
Is it really added and deleted, or moved in each commit (i.e. in each commit appears both as added and deleted)? Because the later seems much more likely.Slobbery
Are the commits done on the same computer? And if not, are they done by exactly the same version of Storyboard?Slobbery
@JanHudec Added in one commit and deleted in another. I could understand moving a block of code but this happens in separate commits. We are 3 delevopers and will look into the two aspects you mentioned.Ordway
@JanHudec Once in a while the storyboard <document ... systemVersion="..."> toggles between 11D50 and 11D50b. Not sure what this is about and if it might be the cause.Ordway
any further word on this? i am in the process of attempting to commit, and the <classes> section is being removed in the iPad.storyboard file, but not the iPhone.storyboard file. the app runs just fine with the <classes> section missing on iPad and with it there for iPhone. fwiw, my commits are via SourceTree rather than internal Xcode or command line.Brocky
@Brocky we figured out it doesn't matter at all. So when we commit or merge, we try to keep the state of the previous commit to keep the noise low.Ordway
Had also been previously asked at #8135662Pamalapamela
N
10

(this answer is based personal experience, and is not a formal one)

The classes section in the .storyboard xml file lists all the view controllers you have in your project in order to

  1. Allow the Assistant Editor show the right source file when you select a UI element in the Interface Builder, and
  2. Allow the Identity Inspector (right panel) to present options for Custom Class.

I guess this section is a cache, being retired when both of the two uses listed above haven't been used for a while.

The fact that this section turned up in the first place implies it is safe to ignore, since it is auto-generated on need. If you already have it committed, and subsequently have it appear as removed on diff, open the Identity Inspector, drop-down the list of classes available under Custom Class, and see how the whole section exists once again.

Neptune answered 7/11, 2012 at 14:48 Comment(1)
This is a very good explanation. But still, is there a way to avoid this? Any way to tell Xcode to keep that section on the Storyboard forever instead of removing it when Xcode feels like it, and adding it back again when you open the Storyboard? It messes with the commits and its bothersome.Umber
R
1

In my experience the removal only happens if you open the storyboard and have class existence related errors. An example of this is opening the storyboard while a merge conflict is not yet resolved. One or more classes might not be parse-able. In this case Interface builder seems to be removing the entire section and not only the offending class.

For me it is easily fixed by opening the storyboard again after the patch is ready in case i see the removal. If all problems are resolved, the section is regenerated. If it isn't, it means I have a problem with project settings and i shouldn't be committing anyways.

Radom answered 25/7, 2013 at 17:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.