60

When I navigate to one of my xib files, Xcode marks the file as touched. Undo and revert have no effect. Saving seems to do no harm, but the glitch causes me frequent additional git work.

Has anyone else seen this or have an idea about something in my MainWindow.xib that would cause it?

Edit in 2019 - still happening!

Dot Freelancer
  • 4,083
  • 3
  • 28
  • 50
danh
  • 62,181
  • 10
  • 95
  • 136
  • I don't see that behavior in my environment. I wonder: Could it be that the xib in question was last used in Xcode3, and Xcode 4 is doing some conversion behind the scenes? Or, are you seeing this any time you select a xib file, whether it's the first time selecting it in Xcode4 or not? Are there any git settings where your file is read-only and perhaps Xcode is changing the permissions so you can edit it? That might account for the modified status. – Mark Granoff May 05 '11 at 15:29
  • Thanks for the ideas. The file had been in an xcode 3 project. The problem occurs every time I navigate to _that one file_. Your conversion idea is a good one, but the issue continues even after a save/build. No special git settings. – danh May 05 '11 at 15:59
  • 2
    Here are the minimal steps with which I can reproduce this problem: xcode->New File...->User Interface->Application xib. Drag a Tab Bar controller in. Save. Select any other file in the project. New xib gets touched by xcode. Diff-ing the original with xcode's mods shows a bunch of tags like this: and and a very large block that opens like this: . Am I nuts? – danh May 10 '11 at 16:54
  • Wow. I see the same behavior, following your steps. I wonder if it's specific to the XIB file being an *Application* xib? You can imagine that that xib has special knowledge about things like your app delegate and such. This is indeed bizarre behavior, that's for sure. – Mark Granoff May 10 '11 at 17:05
  • 1
    Thanks for checking it out. I can reproduce with any xib. The key does seem to be the presence of a UITabBarController. I reported a bug with Apple... bug #9847336. – danh Jul 27 '11 at 05:28
  • xCode 4.5 - affects xib and storyboard. I see no dependance on various elements – MobileVet Sep 27 '12 at 18:46
  • It's back with a vengeance for me. Even sometimes touching one xib when I navigate to another – danh Oct 19 '12 at 15:54
  • This one really bugs me. I simply open a Nib and poof I suddenly have a NSWindow reference or poof it's gone. – Mr Rogers Nov 05 '12 at 16:25

3 Answers3

31

Apple says it's a known issue:

This is a follow up to Bug ID# 9847336. After further investigation it has been determined that this is a known issue, which is currently being investigated by engineering. This issue has been filed in our bug database under the original Bug ID# 9056156. The original bug number being used to track this duplicate issue can be found in the State column, in this format: Duplicate/OrigBug#.

danh
  • 62,181
  • 10
  • 95
  • 136
  • 3
    I cannot see how Apple's own developers would not be annoyed to the point that they would have fixed it by now. – kwahn Sep 13 '13 at 17:21
  • Can anyone else confirm? I'm no longer seeing the problem in 5.0 (5A1413). Hurray? – danh Sep 28 '13 at 19:45
  • 1
    I can still see it 100% in XCode 4.6.3, October 2013! – Fattie Oct 25 '13 at 09:32
  • Just got Version 5.1.1 (5B1008), and the projects I have where this usually happens work fine now. Fixed??!! That didn't take too long. – danh Apr 15 '14 at 02:03
  • I systematically get some `rect` coordinates modified each time I open a storyboard. Now I use to `git checkout` the storyboard after each open (when I do no modification) – Pierre de LESPINAY Jul 21 '14 at 14:21
  • 1
    Yup, I still see it too, though less often on less trivial storyboards. My remedy is git checkout, too. – danh Jul 21 '14 at 14:23
  • 3
    ... and 6.2 with .xibs. :( – cweekly Mar 12 '15 at 02:50
  • 6
    This is bugging me for ages! And only today I decided to google it. Damn that bug must be a hard one to squash. (xcode 6.4...) – Nuno Gonçalves Jul 27 '15 at 09:51
  • Thanks @Das, will be aware about this issue when Xcode 7.3 will be officially released in AppStore. – eugen Feb 22 '16 at 11:23
  • 2
    And still in Xcode 8.2 with XIBs and Storyboards. March 2017. – QED Mar 20 '17 at 21:25
  • 1
    I googled to this question and was wondering if I should upgrade my Xcode to 9 -- hopefully the bug might have been fixed in that version. And when I saw the post date of this answer and all these comments, I found that I was too young and too naive. – zzheng Jan 02 '18 at 21:56
  • @zzheng - I'm on 9.2 now, and so far have not observed this problem. Still not confident, but I think we might be able to call this fixed after six years. – danh Jan 03 '18 at 00:10
  • @danh Thanks for the info! Just upgraded to Xcode 9.2. :-) cross fingers – zzheng Jan 08 '18 at 22:10
  • 1
    I **think** this issue is still present in Xcode **10** and **11**. (I recently upgraded it.) How boring... >.> – Jack T Oct 09 '19 at 09:01
16

After attempting many different solutions to get around this extremely annoying bug, I've found one method that works (it is certainly not a "fix", but a workaround).

Lock controllers when you're done with them.

Select a view controller in a storyboard, open the Identity inspector, and at the bottom in the Document section, you'll see a Lock dropdown. Select "All Properties" from the lock drop down.

If you do this for all of the controllers giving you issues (or just all of the controllers in general, even), you'll notice when you open the storyboard, Xcode will still modify the frames of various elements, but then immediately undo the changes.

This then leads to the development cycle being:

  1. Unlock a view controller
  2. Perform any necessary changes
  3. Lock the view controller
  4. Commit

Locking also works on a view-by-view case if that suits your needs better.

The bug has been around for quite some time now and it doesn't appear to be getting fixed any time soon, so unfortunately this will have to suffice for now.

shim
  • 9,289
  • 12
  • 69
  • 108
Adam Eisfeld
  • 1,424
  • 2
  • 13
  • 25
  • Oh man, I was so excited to find this workaround. This bug has been plaguing and frustrating me for 4 months. Alas, Xcode 6.2 crashes if I lock all properties on the view controller. I even tried moving the lock down to the root view, but it still crashes each time. Dang. Glad you got it working though! – djibouti33 Mar 27 '15 at 06:21
4

I personally feel that knowing that it's a known bug doesn't exactly fix the issue. Here's what I figured out so far and how to keep them from coming up.

NOTE: This is for a storyboard with AutoLayout enabled. I haven't yet figured it out yet for manual storyboards.

Below is an example of a button.

<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Ebd-ny-Ill">
    <rect key="frame" x="97" y="5" width="135" height="30"/>
    <color key="backgroundColor" white="0.94557291669999999" alpha="1" colorSpace="calibratedWhite"/>
    <constraints>
        <constraint firstAttribute="width" constant="86" id="bXV-mS-ksp">
            <variation key="heightClass=regular" constant="135"/>
        </constraint>
    </constraints>
    <fontDescription key="fontDescription" type="system" pointSize="13"/>
    <state key="normal" title="See Full Menu">
        <color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
    </state>
    <variation key="default">
        <mask key="constraints">
            <exclude reference="bXV-mS-ksp"/>
        </mask>
    </variation>
    <variation key="heightClass=regular" misplaced="YES">
        <rect key="frame" x="97" y="5" width="135" height="28"/>
        <mask key="constraints">
            <include reference="bXV-mS-ksp"/>
        </mask>
    </variation>
    <connections>
        <action selector="showMenu:" destination="eQk-yf-uDh" eventType="touchUpInside" id="xOP-Se-FXQ"/>
    </connections>
</button>

If you take a look, you'll see that the button has an element called <rect/> This defines the size and position of the UI item. If you look below, you'll also see an element called <variation/> that describes the change in position based on the size class. In order to fix the position for this, we have to use the following steps:

  1. Take a look at the warning that shows up in Xcode. Take note of what needs to be changed for that UI element.
  2. Open the storyboard in an external (text) editor.
  3. Find the UI element in the storyboard.
  4. Change the value to match what the warning is suggesting in both <rect/> and <variation/>.
  5. Save the file in the external editor.
  6. Go back to Xcode. Let it re-calculate all the constraints.
  7. Accept the warning for the UI element that pops up again.
  8. If you go back to the external editor, you'll notice that the <variation/> element is gone.

In my example, I had to update x="97" to x="597".

I'm still working on elements that don't have a <variation/>. I'll update this answer as soon as I figure it out.

mikeho
  • 6,790
  • 3
  • 34
  • 46
  • Xcode just randomly edits IDs and stuff though, it's not just view constraints and positions. – kevin Apr 16 '18 at 10:23