Building a project in Xcode5.1 that was modified i

2019-02-18 01:11发布

问题:

My app has been supporting at least iOS6 using Xcode5.1 storyboard.

After I did several work in Xcode 6 GM, I need to test on iOS 6 Simulator. Xcode 6 GM does not have iOS 6 Simulator.So, I opened my project in Xcode 5.1.

But It fails to build. I cannot even open the storyboard in Xcode5.1.

At the navigation pane, it says

Main_iPhone.storboard
Interface Builder Storyboard Compiler Error
The document"(null)" requires Xcode6.0 or later.

And when I click it, a prompt appears

The document "Main_iPhone.storyboard" requires Xcode 6.0 or later.
This version does not support constraints to layout margins. Open this document with Xcode 6.0 or later.

回答1:

Adding almost any type of layout constraint with Xcode 6 will render a storyboard (or .xib file) incompatible with Xcode 5.1. If you need to work with a storyboard in Xcode 5.1 that has been modified with Xcode 6.0 it will be necessary to remove all "margin" based constraints.

Perform these steps to make a storyboard modified by Xcode 6 load and compile again with Xcode 5:

Using Xcode 6:

  1. Set the "Opens in" to Xcode 5.1 in the Interface Builder Document Section of the storyboard File Inspector. When this is set, Xcode 6.0 will generate a warning if there are any incompatible margin constraints present.

  2. One easy way to identify the margin constraints is to open the storyboard in a text editor (preferably one that auto refreshes when the file is changed on disk). Search for the word "Margin" and look for lines like this:

    <constraint firstItem="gZc-ET-UKM" firstAttribute="leading" secondItem="MMQ-IT-qOo" secondAttribute="leadingMargin" constant="-8" id="H3i-wo-2Mm"/>
    
  3. These constraints need to be either deleted or updated to be based directly on the superview rather than a margin. It is possible to update the constraint instead of deleting it by selecting the constraint in the outline view and then going to the Size Inspector and unchecking "Relative to margin" option in the drop down menu for the First Item or Second Item settings. Once you do that, you'll also need to add a constant that matches the margin (usually 8).

As you delete or update each constraint you should see the storyboard file in the text editor update and remove the word "Margin". Once you have deleted all of the incompatible constraints the warning will go away and this line will disappear from the storyboard file:

    <capability name="Constraints to layout margins" minToolsVersion="6.0"/>
  1. If you deleted the constraints, the final step is to open the project in Xcode 5 and recreate them.


回答2:

I encounter the same problem, and here is my solution:

Suppose the problem file is Main.storboard

  1. Using Xcode 6 open project;
  2. Select Main.storboard open as source code;
  3. Search "margin" in source code;
  4. Uncheck relative constraints' relative to margin in Interface Builder.


回答3:

You can change this option in the identity inspector on right side. Select your Storyboard in Xcode 6, open the identity inspector, then Interface Builder Document -> Opens in Xcode 5.1 (or something other)



回答4:

select your nib file or storyboard, select file inspector pic 1. And uncheck use size classes (pic 2) in every storyboard, you created with xcode 6, because by default it checked.



回答5:

Although, I don't think this is ultimate solution, ,for the time being I am writing, I just ignored that "RED ERROR" and hit the Run.

It launched iOS6 simulator and worked fine. All I had to is quitting the simulator launched by Xcode 6.

The error message is still there and I cannot open the storyboard file in Xcode 5.1.

but at least I am able to test it on the older version of iOS. So now Xcode5.1 is only for the testing, for my application :(

If you find better solution, anwwer the question. Thanks.