17

I am trying to merge two .nib files. FileMerge has no problem showing the comparison of the two files. I am trying to keep all the settings in one file (i.e. right side) except for two settings that I want to copy from the other file (i.e. left side). The differences are just one line of code each that changes the integer value of a autoresizingMask key. So it shouldn't be hard to merge. I would use TextEdit if it would allow me to open a .nib file.

However I get the error "This file type cannot be merged." I tried playing with the FileMerge > Preferences > Filters settings for the .nib extension as mentioned in the answer to a similar question posted on this site but had no luck. As far as I can tell the Display setting should be left as "Filtered" for a .nib since unfiltered it is not readable and I tried toggling the Apply selection. I assume that the actual Filter used should itself not be changed or modified?

Is there any common reason why two .nib files that FileMerge has no problem showing in the comparison window cannot be merged?

Thanks

Mike
  • 331
  • 2
  • 9

3 Answers3

5

XIBs can be merged. In simple cases (like text changes, elements resized) it's safe and easy, and latest XIB versions can survive even more complicated merges (Apple has been upgrading the format, and nowadays it's reasonably readable and doesn't use numeric IDs that used to make merges error-prone.)

The problem is that FileMerge has hardcoded built-in configuration to filter XIB files through ibtool pretty-print, and that makes it say they're not mergeable.

// edit: it looks like Apple has added verification of executable's integrity, so patching solution doesn't work any more. "Stop using FileMerge" is the solution now.

Some tips:

  • Enable "Compress whitespace" option in FileMerge Preferences.

  • When the diff is a total mess and XIB files appear to be completely different, they're probably different versions of the format. Run this on each XIB file, before merging (on pristine files without merge conflict markers):

    ibtool --write foo.xib --upgrade foo.xib
    

This will convert XIB files to latest Xcode version, so both will have the same structure.

Kornel
  • 91,239
  • 30
  • 200
  • 278
4

NIB and XIB files cannot be merged, however tempting it may be. It may be useful to look at a diff using FileMerge, but only use this information to inform which changes you manually recreate in Interface Builder.

Additionally, FileMerge does not show the actual text diff of the NIB files, but rather the output from ibtool. You can see the actual text diff by deleting the entry for NIBs in the FileMerge preferences, but this setting is not saved between launches of FileMerge.

Joey Hagedorn
  • 2,368
  • 18
  • 21
  • You are exactly right. A nib/xib is an apple version of an XML called a property list (abbreviated plist. Maybe you have seen these in the resources file templates). To prove this, right click on the nib/xib go to 'Open As' and click 'Property List'. No other file (except a .plist) can be opened this way. To change back, go back to 'Open As' and click 'Interface Builder' – Chase Walden Nov 10 '11 at 04:17
  • 1
    Chase, that's not quite correct. XIB files are not plists; simply by being XML doesn't imply that something could be merged. One of the reasons merging doesn't work is because the object graph represented by a nib is not purely hierarchical, meaning there is are additional relationships diff/merge doesn't know how to maintain. – Joey Hagedorn Nov 23 '11 at 21:03
2

.xib files are text -- they should work, especially the modern ones which are more like storyboard files. FileMerge, however, has in its Filter preferences a section for xib files -- it compares processed output rather than the original files. This prevents the merge from being saved.

Simply deleting the "xib" entry in the preferences should theoretically work -- but whenever I try to delete that filter line, it seems to come back when I re-launch FileMerge. So, that approach does not seem to work.

What does seem to work is to simply change the filter command in the second column to cat (i.e. remove the "ibtool" command and its arguments, and replace with just "cat", which will result in a straight copy of the original file) -- and then choose to display the "Original" rather than "Filtered" in the third column. At that point, FileMerge (without hacking the binary) seems fine when saving merged .xib files.

This will not work with binary .nib files, but those are no longer directly edited, so that should not be a big issue during merges.

Carl Lindberg
  • 2,822
  • 16
  • 21
  • While this did work for merging, it oddly somehow caused Xcode to fail building my project. I had to revert the new FileMerge filter setting for xib, then Xcode would build the project successfully. – duncanc4 Jul 12 '17 at 10:45
  • Which version of Xcode ? I have not seen that problem (Xcode 7.3 and Xcode 8.3.3). That behavior would seem to be utterly bizarre. The build process should not normally use FileMerge stuff, unless there are custom build scripts (or build rules) which somehow do. – Carl Lindberg Jul 12 '17 at 13:40
  • At least under Sierra, I can build multiple projects just fine with that setting in FileMerge using Xcode 8.3.3. Has worked on previous Xcode/OS versions too. They really shouldn't be related either. What is the failure you get? – Carl Lindberg Jul 13 '17 at 13:04