43

This is a problem we never had to deal with until storyboards were introduced - Whenever there was a chance of conflict in UI, we just made sure that no 2 developers ever worked on the same XIB file simultaneously. The reason we refrained from resolving XIB conflicts is that there may be problematic side-effects (XIB is represented in XML format so there isn't a "good" way to merge 2 versions).

Now we are facing this issue because all of our UI elements are within the same .storyboard file - prevention of simultaneous work on any 2 UI elements in the project makes working in parallel very difficult.

Any suggestions as to how to tackle this issue? Thanks in advance for your efforts.

Stavash
  • 14,244
  • 5
  • 52
  • 80
  • 3
    Ouch. This is a good question! – Ben Clayton Jul 18 '12 at 09:43
  • 1
    Hope it also helps future generations :) – Stavash Jul 18 '12 at 09:44
  • Have you tried adding to your svnignore this `YourProjectName.xcodeproj/project.xcworkspace/xcuserdata/yourusername.xcuserdatad/UserInterfaceState.xuserstate` . I work with one more developer on a same project and we haven't got those problems, we use git but it's the same thing, that is what I've got in my .gitignore – ant Jul 18 '12 at 13:34
  • The user state is ignored, my problem is with the storyboard file - ignoring it will not help as we DO need to be able to merge it – Stavash Jul 18 '12 at 14:37
  • Similar to http://stackoverflow.com/questions/8393214/xcode-storyboard-merging – Dustin Jul 20 '12 at 14:02
  • @Dustin, not exactly - I'm specifically trying to avoid merging these files as source code. Also, this is defined as an SVN-specific problem. – Stavash Jul 20 '12 at 14:03
  • Best way I found during facing same issue. a great description is here at http://datacalculation.blogspot.in/2014/09/best-way-to-avoid-merge-conflicts-with.html – iOS Test Oct 07 '14 at 04:36
  • @iOSTest That's the same approach as described by the accepted answer. – Stavash Oct 07 '14 at 06:55

4 Answers4

39

Break up your storyboard into multiple storyboards.

There is no reason for your app to contain only one storyboard. Break your storyboard up into module storyboards. You can use +storyboardWithName:bundle: to load storyboard modules.

See: UIStoryboard Best Practices for other good storyboard ideas.


Update

It's important to note this is not a complete solution to the problem. In the same way you cannot completely avoid the possibility of merge conflicts in source code decomposing a giant class into smaller modules, you can't avoid the possibility storyboard merge conflicts either. The idea is to reduce the likelihood until it becomes a manageable problem.

There will alway be tricky merge situations in a large codebase. A properly decomposed solution will reduce the number of conflicts and minimize the number of lock out needed.

Jeffery Thomas
  • 42,202
  • 8
  • 92
  • 117
  • But what if there are important relations and segues that I want between all of my application's UI elements? – Stavash Jul 20 '12 at 12:10
  • It's up to you and your project's needs how best to break-up a monolithic storyboard. If you find that you are transitioning all over the place and are unable to decompose your storyboard, then your problem may not be storyboards as much as spaghetti UI. – Jeffery Thomas Jul 20 '12 at 12:35
  • 1
    We are actually very capable of managing all of our UI via the storyboard. As for the question of the ability of decomposition is irrelevant because that's the whole point of storyboards - if we break everything down we can just as well go back to separate XIBs. – Stavash Jul 20 '12 at 12:46
  • If you believe that decomposition is irrelevant for your project, then this may not be a good solution for you. For me, it was easy to break my storyboard up into 5 separate, but related storyboards. – Jeffery Thomas Jul 20 '12 at 13:19
  • 2
    This is an interesting idea. I was not aware that one could use multiple storyboards but that makes A LOT of sense. Many times our projects are divided up between "flows" of user activity, and typically a developer is assigned to a particular Flow. So this could address that kind of approach. – Evan K. Stone Dec 05 '12 at 17:03
  • I got best answer here at http://datacalculation.blogspot.in/2014/09/best-way-to-avoid-merge-conflicts-with.html – iOS Test Oct 07 '14 at 04:35
0

Here's something I came up with when I was just messing around, trying to find a solution.

If you right click your storyboard file in Xcode and navigate to "Open As" you'll see that there are multiple options - the default is "Interface Builder - iOS Storyboard". However, you can also select "source code".

If you open storyboard up in source code mode, it's possible to make changes (although kind of a pain). But you can add code from other storyboards and make changes in your own - I haven't used SVN but with a git repository I can view other versions of the storyboard and copy code in.

I wouldn't say that this is a great solution - I've had some trouble with Xcode randomly crashing when I try to reopen the storyboard in IB. Sometimes pasting code in works, sometimes it doesn't. A few times I had to change the <scene> tag's value. In my experience it's pretty hit-or-miss but if you back up your files before you try anything it might work.

If it does work, let me know - I'm interested in seeing whether a solution can be found to this problem.

Dustin
  • 6,783
  • 4
  • 36
  • 53
  • Thanks Dustin. The crashes you described were experienced by myself lots of times in the past and are the reason I'm trying to avoid editing the Storyboard files as XML source. – Stavash Jul 20 '12 at 13:54
0

Is this about merging XML files?

Fortunately, SVN allows you to change the merge tool you use to perform merging for different types of file. (eg tutorial for using P4Merge)

So now you just need to find a great tool for merging XML files (good luck :) )

there's WinMerge (with the DisplayXMLFiles prefilter), or diffxml, or XMLMerger or a java xmlmerge tool

gbjbaanb
  • 51,617
  • 12
  • 104
  • 148
-3

You can also have a look at a modern source code management tool. Git for example has intelligent merge features. See this link for why you should consider upgrading your workflow.

Community
  • 1
  • 1
user1534610
  • 70
  • 1
  • 1
  • 6
  • Although this makes a good point, using any other tool other than SVN is a big problem - all of our projects are managed by SVN and we would have loads of code revisions to transfer to GIT. Will check the option though. Thanks. – Stavash Jul 20 '12 at 12:19
  • Have a look at git-svn if you consider migrating. It is a tool that kind of synchronize a git and a svn repository. It can be useful as a start. – user1534610 Jul 20 '12 at 12:45
  • 5
    I don't think you can merge storyboards with Git. I use it and I still get my storyboards overwritten... – Dustin Jul 20 '12 at 14:07
  • Git has many of the same shortcomings as SVN when it comes to merging storyboards. Sometimes it works, sometimes it doesn't. We're using Git and we have to very often use FileMerge or some other tool to fix the merge. – Evan K. Stone Dec 05 '12 at 17:06
  • 2
    Just wanted to add another comment that `git` is anecdotally no better at merging storyboards or pbxproj files. – ray Jan 03 '13 at 19:39