Search code examples
iosswiftxcodestoryboardxib

Xcode 8.x hangs too much in the XIB files


I am using Xcode 8.1, Storyboard files are working well but whenever I open the XIB files, Xcode sucks and started hanging. Please let me know, what is the issue with this buggy Xcode.

Or should I look for any other alternative?

Thanks


Solution

  • I have a 3.4 GHz Intel Core i7 with 32 GB 1600 MHz DDR3, 2 GB GTX 680MX and Xcode will hang. I'll admit that I don't always see a difference between editing a .xib and .storyboard but Interface Builder seems to be a "bad citizen" when it comes to resources in general. As a result I have changed my work flow a little to avoid those moments of frustration and get work done.

    1. Avoid IBDesignable if possible.

    If they do actually work/load properly they are at best just showing you what you could see by simply running your app. If I'm prototyping a custom control/view I will use a playground with PlaygroundSupport and a liveView. Note that I'm not saying IBInspectable is bad. I use it all the time.

    2. Use Xcode's "Editor > Refactor to Storyboard" as an alternative to xibs and large storyboards.

    One thing that seems to help me is to use small storyboards in a way thats like using xibs. Although it is possible, I'm don't strictly mean one storyboard for every view controller. More along the lines of one storyboard per process in your application. For example, I usually give a signup process its own signup.storyboard that only contains scenes relevant to signup. This has the advantage of bundling multiple scenes and preserving the ability to use segues while, being just as flexible as xibs, enabling you to switch between UI versions by simply changing which storyboard file you load.

    Code Example

    For example, in initial view controller of a signup process storyboard I will create the following:

    public class func instantiateFromStoryboard() -> SignupViewController {
        let storyboardName = "Signup"
        let storyboard = UIStoryboard(name: storyboardName, bundle: nil)
        let storyboardIdentifier = "SignupViewController"
        let signupVC = storyboard.instantiateViewController(withIdentifier: storyboardIdentifier) as! SignupViewController
    
        return signupVC
    }
    

    Update: I have created a simple UIViewController extension that is essentially the generic version of the code above. See the readme for details. https://github.com/kyleishie/InitFromStoryboard

    Storyboard Only Example

    This can be accomplished, without code, with only storyboards as well by using cross storyboard segues. In the object library while editing your storyboard there is an object called Storyboard Reference. Drag one out and set its Storyboard property to the destination storyboard. You can now create segues to the destination in the way that you would expect. If desired you can specific a specific scene to by entering its storyboardIdentifier as the Referenced ID. By default it uses the storyboard's initialViewController.

    Using this method, or something similar, you can easily swap out the entire signup process UI by

    • Creating a new storyboard with the appropriate scenes.

    • Assigning the existing classes to the new scenes and wire up all of the outlets and actions.

    • Change the storyboardName above in the initialViewController or storyboard property in the storyboard reference object that segues to this process.

    Ray Weinerlich has a good tutorial on using storyboards with iOS9+.

    I realize that this workflow may not be exactly what you are asking but it may help with your particular issue if storyboards are working well but xibs aren't. ;)