7

I have an issue where my storyboard failed to render the layout, so I can't add constraints and also can't see the layout of my viewController.

Issues Image

How can I resolve this?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ben10
  • 3,221
  • 2
  • 34
  • 61
  • This sort of thing is usually fixed by restarting Xcode and/or your Mac. This will restart the agent and allow it to start rendering your UI again. Have you tried this already? – siburb Apr 23 '19 at 06:54
  • @siburb Yes I was tried many times restrat and deleting derive data folder – Ben10 Apr 23 '19 at 06:56
  • Please review *[Why not upload images of code/errors when asking a question?](https://meta.stackoverflow.com/questions/285551/)* (e.g., *"Images should only be used to illustrate problems that* ***can't be made clear in any other way***, *such as to provide screenshots of a user interface."*) and take the appropriate [action](https://stackoverflow.com/posts/66101455/edit). – Peter Mortensen Jun 21 '22 at 13:30
  • IB = [Interface Builder](https://en.wikipedia.org/wiki/Interface_Builder) – Peter Mortensen Jun 21 '22 at 13:38

2 Answers2

2

All the previous answers did not help, but I figured it out.

In the @IBInspectable didSet property I was calling the common setup() function to utilize my view. However, I was trying to adjust a textField without checking whether it was nil or not. That's why I was getting "failed to render" problem and also a run time crash.

For example:

@IBInspectable var isTitleEnabled: Bool = true{
    didSet{ setup() }
}

And the setup() function was:

private func setup(){
    textField.isSecureTextEntry = isPassword
}

which is wrong. Xcode doesn't allow the subviews to be modified in this way.

When the Interface Builder (IB) component is rendered, Xcode thinks that it is not initialized yet, so it raises an error. To solve this misunderstanding, we need to make sure that the Interface Builder component is not nil.

So, instead we need to use it like that:

guard textField != nil else { return }
textField.isSecureTextEntry = isPassword ? true : false

The Interface Builder component don't need only to be a UITextField. It is valid for other Interface Builder components like UILabel, UIImageView, etc.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Eray Alparslan
  • 806
  • 7
  • 12
1

See the answer @IBDesignable error: Failed to update auto layout status.

Or just try go to EditorRefesh All Views in your Storyboard selection.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sterli
  • 49
  • 1
  • 8