Why is my XIB modified every time I open it in IB?
Asked Answered
S

4

45

I click on the XIB via the project navigator. It opens up and immediately changes the icon to gray showing I have unsaved changes. If I save changes, click on a different file and click back to re-open it, more changes. Always modifies on open.

It happens with one XIB file in this project and a couple in another project. I'd love to know why it's happening and what I can do to fix it now and prevent it in the future.

Note: using Xcode 3.2 Build 4C199 with Snow Leopard

Edit: I've added a couple sections which got removed from the XML on one of these open/modifications

        <key>outlets</key>
        <dict>
            <key>addEventTabBarController</key>
            <string>UITabBarController</string>
            <key>window</key>
            <string>UIWindow</string>
        </dict>
        <key>superclass</key>
        <string>NSObject</string>

and

        <key>outlets</key>
        <dict>
            <key>courseTableCell</key>
            <string>UITableViewCell</string>
        </dict>
        <key>superclass</key>
        <string>UITableViewController</string>
Scanner answered 4/11, 2011 at 0:28 Comment(1)
I've got one that gets modified if you have it open and then move away from it.Countershaft
S
24

I wound up submitting this issue to Apple. Their response was unenlightening, and talking about possible optimizations, updating meta data for new version of Xcode and the like.

I tracked 100 versions from clicking off and on the file. As Apple said, it was "optimizing" every time, but each time it simply moved some XML tags around. Never happy with it's own optimizations it moved them around the next time they were opened. I'd consider it a bug with Xcode, annoying, but mostly harmless.

This only happened with old XIBs and either moving the contents into a new XIB file or (what really happened) Storyboards got rid of the issue.

Scanner answered 24/9, 2012 at 16:15 Comment(2)
Seems to me that if they want to optimize such things, they should take the same approach as they do with optimizing the build configuration and at least ask the user before making such changes...Pissed
Even this happens in Xcode 6 & 7.... I think this will never be fixed by Apple the creator of Xcode! Shame!Knave
T
6

I did not want to use storyboards as suggested in one of the other answers. Here is an alternative simple/quick fix.

Go to the Interface Builder Document Properties on the inspector when selecting the xib view file. Then you need to

  • change "Deployment" to something different from Project SDK, in my case I set it to the latest iOS version (iOS 6 currently).
  • change the development to something different from "Previous version", in my case I set it to the latest Xcode version 4.5

I run Xcode 4.5.2 on Lion.

Hope this helps.

Twopenny answered 23/11, 2012 at 21:3 Comment(1)
This is great, helped me out!Legend
P
4

basic Idea...

XCode stores lots of version numbers of all different sorts of things. If you look at the XML representation of the XIB, you should find that the vast majority of these little changes are in these version numbers.

How it happens...

Whenever you do an update of Xcode, many different things within Xcode (and often inside the SDK) get updated. If you make a change to a XIB file, those version changes get stood in the XIB. So, if you happen to open a XIB file, the version changes get put into that file. As soon as you build or run the app, those changed get saved to the file.

But I haven't update Xcode in a while!

Well, whenever you did your last update, the XIB files will be updated with the new version numbers as you open them, one-by-one over time.

Plante answered 13/12, 2011 at 4:13 Comment(1)
While I have no doubt it's possible for XCode to re-structure and modify files between versions, that isn't what's going on here. I can open/modify and save the changes 50 times over 5 minutes if I just keep opening the file and saving the changes. I've also taken a look at the modifications and they seem centered around outlets and other sections which would seem like it could cause the file to break... but it still works so it shows how little I know on how the xml inside XIB file works.Scanner
H
0

Edit XCode 4 is better now, (maybe), if you're tempted to vote this down then ask yourself, "Have I migrated from XCode 3 to XCode 4 using Versioning?" If no, then you have no idea what you're doing, and please don't vote on this. If you have, you know how bad you suffered, but yes this question is otherwise dead. If you do find yourself opening a legacy project, just recreate it and copy the files.

I don't know the exact answer, but I do know these things will help you find it:

XCode 4 is notorious for screwing things up. If you put your directory into a Versioning system, (Git), then grab GitBox and save your project to give it a state and create a git repo out of it. The git repo will save the state. Gitbox will visually show you the changes.

After opening it, you'll be able to right-click on that file in GitBox and hit "see difference" or "view changes" or whatnot.

You will be auto-scrolled to the lines. If you can relate the XML to the Xib, you can figure out what changes.

I went from Lion to Snow Leopard, so I don't deal with this anymore.

Hadden answered 4/11, 2011 at 4:2 Comment(3)
I am using revision control have have taken a look at the changes. Sometimes I swear it's just moving XML around the file. Other times it makes actual changes which look like they would affect my various components... but have 0 noticeable impact when I run my code. I wouldn't be surprised if it just keeps flipping between 4 different "changes"Scanner
You say going from Lion back to SL fixes this anomaly? Is it the Xcode version that is making the differences or the OS? Is Lion's versioning possibly kicking in?Biogeography
I never switched to Lion, I've been using Snow Leopard the whole time and obviously I have this problem. :)Scanner

© 2022 - 2024 — McMap. All rights reserved.