@IBDesignable crashing agent

When I write my own UIButton-extended class and make it @IBDesignable, I receive two errors in Interface Builder, namely:

  • Main.storyboard: error: IB Designables: Failed to update auto layout status: The agent crashed because the fd closed
  • Main.storyboard: error: IB Designables: Failed to render instance of RandjeUIButton: The agent crashed

Here is my code:

import UIKit

@IBDesignable
class RandjeUIButton: UIButton {
    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)

        self.backgroundColor = UIColor.blackColor()
    }
}

I am working in Xcode 7 beta 2 on OS X 10.11 beta 2. (Running in VM)


Solution 1:

Xcode's Interface Builder requires that you implement both or neither initializers for @IBDesignable classes to render properly in IB.

If you implement required init(coder aDecoder: NSCoder) you'll need to override init(frame: CGRect) as well, otherwise "the agent will crash" as seen in the errors thrown by Xcode.

To do so add the following code to your class:

override init(frame: CGRect) {
    super.init(frame: frame)
}

Solution 2:

I've met the same problem and solved it this way:

  1. The Problem:

error: IB Designables: Failed to update auto layout status: The agent crashed

  1. Find the debug button in the inspection file and click it.

debug

  1. Then the Xcode will tell you where the prolem is. In my case I drop the IBDesignable before the class.

  2. Then I clean and rebuild it, the error disappeared

Solution 3:

There are a myriad of problems that can cause this. Fire up Console, and look for the crash report IBDesignablesCocoaTouch...

I just sorted out a problem with a 3rd party designable which had issues with the valueForKey semantics.

Solution 4:

In Xcode 7.3, none of the above solutions worked for me, but the accepted answer to this question did: Failed to render instance of IB Designables

  1. Clear Xcode derived data for the project. They are in ~/Library/Developer/Xcode/DerivedData
  2. Clean your current build by pressing ⌘⇧K
  3. Build your project
  4. In storyboard go to Editor menu and do Refresh All Views; wait for build to be completed and errors should be gone

I did not need to do the 4th step to solve the problem (and get my PaintCode-drawRect'd UIView to paint in the storyboard), included here just in case.

Credit to @Mojtaba and @WeZZard