188

I recently upgraded to Xcode 8 and I am having issues with the Storyboard.

If I open the project and I don't have the Storyboard open, it will compile and run just fine. Once I open up the Storyboard, I get multiple errors about IB Designables as shown below.

enter image description here

These views are the only views that are using custom views from TextFieldEffects and BEMCheckbox that I imported using Cocoapods.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Alan
  • 9,331
  • 14
  • 52
  • 97
  • Maybe check the repository for the Pod you're using and see if this issue is prevalent among other users? – Zolnoor Sep 27 '16 at 18:55
  • Any relevant answer to this? – Mohsin Khubaib Ahmed Nov 29 '16 at 14:45
  • 1
    did you guys find any workaround ? – dip Jan 13 '17 at 12:49
  • 1
    Watch out, the problem can be **YOU NEED A FAT BUILD for an embedded library**. in my example I had Swifter embedded. Naturally you keep on hand a fat build (for development - simulator/phone) and a phone-only build (for app store, phone only) and you just swap to the phone-only one when needed to submit to TestFlight etc. I still had the phone-only library in the project!!!!! Doh! Swapping to the "correct" fat on fixed the problem. – Fattie Aug 02 '19 at 16:10

24 Answers24

203

You can try one of the following to figure out the cause:

  1. look for the IBDesignablesAgentCocoaTouch logs in this directory: ~/Library/Logs/DiagnosticReports and see the cause.

Note: for user with Catalina: look for IBDesignablesAgent-iOS_<DATE>-<MAC_NAME>.crash

  1. Go to the Editor -> Debug Selected View while selecting your @IBDesignable UIView in your storyboard, and see the stack trace.

  2. Delete Derive Data folder.

    Xcode Preference -> Location -> Derived Data
    /Users/YourMacName/Library/Developer/Xcode/DerivedData
    
  3. Clean your project Shift + Command + Alt + K.

  4. Build your project Command + B.

hbk
  • 10,908
  • 11
  • 91
  • 124
Maria
  • 4,471
  • 1
  • 25
  • 26
  • But my problem is that it only happens sometimes for the same storyboard. – Bagusflyer Aug 14 '17 at 01:59
  • Exactly, It happened sometimes in my projects. – Shahabuddin Vansiwala Nov 15 '17 at 07:30
  • 36
    Using this approach I was able to find out that the reason was `Fatal error: Use of unimplemented initializer 'init(frame:)' for class 'TestIBKit.Button'`. I didn't know that `IBDesignablesAgentCocoaTouch` process calls `init(frame:)`, instead of `init?(coder aDecoder:)`. – Yevhen Dubinin Dec 03 '17 at 16:08
  • 6
    @YevhenDubinin Thank you, this helped me. Everything was fine after I implemented `init(frame:)` in my UIButton subclass – Aero Apr 14 '18 at 10:25
  • 1. Log wasn't there. 2. I clicked the problematic view, then editor then debug selected view. It said it debugged it, but where do I find the stack trace? It isn't in the debugger, isn't in the file navigator. – ScottyBlades May 02 '18 at 19:24
  • 3
    This fixed my issue, But I had to quit xCode before deleting derived data – Husam May 29 '18 at 22:00
  • I fixed this problem by rebooting mac. – Kimi Chiu Jul 24 '18 at 12:33
  • 2
    the best answer init(frame:) is common issue – Michał Ziobro Oct 16 '18 at 11:22
  • This is the better way understanding problem. – dip Oct 30 '18 at 04:31
  • 3
    Quit xcode and clear DerivedData. It solved the issue. – Mubashar Jan 28 '19 at 11:09
  • I was getting a crash because my view was overriding layoutSubviews() within which I was doing some setup that involved a force-unwrap. The result was an exception due to force-unwrapping a nil. I solved it by putting a guard statement in to only attempt further setup if the optional was there. The view as mostly blank wheile playing around with in the interface builder, but it didn't crash anymore. – James Dobson Feb 27 '19 at 15:38
  • looking for the IBDesignablesAgentCocoaTouch logs saved me! Thank you very much! – echo May 23 '19 at 17:08
  • after 2 hours of searching, the best answer to find the real cause. – umair151 May 27 '19 at 08:02
  • This, being able to locate the logs, this was it. Thank you. – leopic Oct 01 '19 at 14:36
  • Thanks for the tip to find the logs. That helped find the issue, but not sure how to fix it: I reference a named color from my assets as `UIColor(named: "MyColor")`: while it works in the app, it returns `nil` here in the storyboard and crashes... any idea why? – agirault Nov 22 '19 at 20:43
  • @agirault just add a default non nil color like `UIColor.black`. this will just satisfy IB, runtime will work just fine – Radu Ursache May 13 '20 at 11:38
  • Thank you. Your answer helped me fix a bug. – Abrcd18 Mar 03 '21 at 17:55
98

I solved the problem by doing the following:

  1. Go to File > Workspace settings.
  2. Click the little right arrow beside "Derived data". This opens the Finder app at the location of the DerivedData folder.
  3. Go inside the DerivedData folder, and delete the folder corresponding to your project.
  4. Quit Xcode, and re-open it.
  5. Clean your project shiftcommandk.
  6. build your project commandb.
  7. Open your storyboard.
  8. Go to Editor > Refresh all views.

Updated

Sometimes just directly Go to Editor > Refresh all views worked. If Refresh all views is disabled, quit Xcode and try again.

axunic
  • 2,256
  • 18
  • 18
  • Thank you for posting this. I did an "old school" command line deletion of derived data, but the problem persisted. Using your method resolved the problem for me. – Adrian Mar 25 '18 at 01:27
  • Refresh all views for the win for me as well. Thanks! – Mike K. Jun 07 '20 at 19:19
  • Second time your answer has saved me – Frakcool Jan 30 '21 at 23:48
  • I tried everything and even deleted the full `DerivedData` folder multiple times but it didn't get rid of the error messages until I restarted the Mac after step 4 (quit Xcode, restart, then open it again). – Neph Jun 01 '21 at 12:37
60

I just delete the view that is failed and press command+Z to undo deletion. It works for me.

If editing the failed view later, the error may occur again, do the above again.

yancaico
  • 1,145
  • 11
  • 21
37

I faced this issue in CocoaPod 1.5.0. The solution is to reinstall pod again (pod install again) once this error showing or you may use CocoaPod 1.4.0 instead. It works fine in 1.4.0 (at least for me.)

update:

Add following script in Podfile help me solve the issue in 1.5.0

post_install do |installer|
  installer.pods_project.build_configurations.each do |config|
    config.build_settings.delete('CODE_SIGNING_ALLOWED')
    config.build_settings.delete('CODE_SIGNING_REQUIRED')
  end
end

reference: https://github.com/Skyscanner/SkyFloatingLabelTextField/issues/201#issuecomment-381915911

Jerome Li
  • 1,492
  • 14
  • 20
18

Adding following code to my @IBDesignable class did the trick.

override init(frame: CGRect) {
    super.init(frame: frame)
}
Mohammad Zaid Pathan
  • 16,304
  • 7
  • 99
  • 130
  • This works for me. In fact, I added two override for extending `UITextView`. (1) `init(frame: CGRect, textContainer: NSTextContainer?)`, (2) `init?(coder aDecoder: NSCoder)`. Then rebuild and warning (error) gone. No even need to clean build folder. – John Pang Nov 10 '18 at 02:03
  • Thanks! Good answer ) – JiosDev Apr 15 '20 at 11:28
17

If you're using xib file for custom uiview. Try this:

Change from

Bundle.main.loadNibNamed("UserView", owner: self, options: nil)

To:

let bundle = Bundle(for: UserView.self) 
bundle.loadNibNamed("UserView", owner: self, options: nil)
Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
16

For anyone -like me- who can't find that IBDesignablesAgentCocoaTouch file or when trying to 'Debug Selected Views' from the Editor gets an error, here's another way to debug those "Failed to render" errors.

Open the 'Console' app, from the sidebar select your current Mac (it will probably be auto-selected by default) and then on the search bar search for "IBSceneUpdate" and hit enter.

This way, every time you get an Xcode error for an IBDesignable not being able to render, you will also get a new "IBSceneUpdate" entry with more details about the error.

That's at least how I was able to debug my IBDesignable errors!

Console app showing IBSceneUpdate errors

Stelabouras
  • 454
  • 5
  • 12
  • 1
    The app is actual Console rather than Terminal just as an FYI. – Carl Upton Aug 08 '19 at 11:01
  • Good catch! Edited my answer. – Stelabouras Aug 09 '19 at 12:20
  • In Catalina, in the Console, under All Messages I get a Crash Reports item and clicking this showed all the IBDesignablesAGen-iOS errors. The other answers gave only temporary fixes, but the error description in the Console showed me exactly how to permanently fix the error. – MangoLassi Oct 02 '20 at 16:22
9

My problem was solved by deleting folders (which is related to this project) from the derived data folder.

You can do this by:

  1. Clicking menu FileProject Setting

  2. Click the arrow sign deside /Users/.../Xcode/DerivedData.

  3. Click the DerivedData folder. You will see your project named folders. Delete those.

  4. Quit Xcode and then open your project.

  5. Clean the project by using this step: ProductClean.

  6. Then build the project: ProductBuild

These will resolve these problems.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mitu Vinci
  • 455
  • 9
  • 21
  • What do you mean by *"deside"*? Do you mean *"inside"?* Or something else? Please respond by [editing (changing) your answer](https://stackoverflow.com/posts/45475663/edit), not here in comments (***without*** "Edit:", "Update:", or similar - the answer should appear as if it was written today). – Peter Mortensen Jun 21 '22 at 14:26
8

Try to disable 'Use Trait Variations' (Identity and Type panel) for any xib file that you might have for custom views that are used in your storyboard.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
LatinCoder
  • 81
  • 2
  • 4
7

Correct answer provided by @Maria:

check crash report at ~/Library/Logs/DiagnosticReports

Alternative way:

  1. Open Spotlight

    Enter image description here

  2. Type console.app

    enter image description here

  3. Select Crash reports

    Enter image description here

  4. Check one for IBDesignablesAgent-iOS and review crash log

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
hbk
  • 10,908
  • 11
  • 91
  • 124
  • 1
    Using Console was what helped me solve my problem. Much more detailed messages than what was in Xcode. – Andrew Moore Jun 16 '20 at 13:38
  • 2
    Spotlight solution is simple and requires zero neurons from being burned. If your brain is already a bit overworked and can't follow directions this is it! :D – Jona Aug 13 '20 at 14:25
6

I tried clean and run the project won't solve this issue.

But Close and reopened the project did.

Lal Krishna
  • 15,485
  • 6
  • 64
  • 84
4

Just open your storyboard -> Editor -> Refresh all views. This work for me.

4

I had the same issue and came here to try and figure out what happened. I noticed the top rated answer and the answer itself didn't help me, as IBDesignable didn't exist in the log folder and I already attempted all other options there, however in the comments I noticed someone talking about a frame init.

I decided to try commenting out my IBDesignable extension for UIView and it instantly fixed the problem. So, to fix this, find the extension causing the issue and make sure to set up the required inits by creating an IBDesignable class and providing the required initializers as follows:

@IBDesignable class RoundedView: UIView {

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

required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    sharedInit()
}

override func prepareForInterfaceBuilder() {
    super.prepareForInterfaceBuilder()
    sharedInit()
}

func sharedInit() {
}
}

IMPORTANT: remember to add the new class to the item you are using the designable on.

Nox
  • 1,358
  • 1
  • 13
  • 25
  • 1
    As its documentation says, don't forget to call super.prepareForInterfaceBuilder() in your implementation of prepareForInterfaceBuilder(). – Jaime S Nov 19 '18 at 17:11
3

When I debugged this, I found out there are some classes which are modifying the UI. Typically marquelabel which is a subclass of UILabel or any other class subclassing UIView and drawing UI at run time and colliding with Autolayout engine. Try giving a fixed width or height for these custom views. If it doesn't solve your problem try the following solutions:

Solution 1: Uncomment #use_frameworks inside your pod file.

Solution 2: Try deleting derived data

  1. Close the Editor window of your Xcode and quit the simulator
  2. Go to Xcode PreferencesLocations
  3. Click the small grey arrow showing the derived data path
  4. Select your project
  5. Delete all the folders inside
  6. Quit Xcode and reopen
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ashish P
  • 1,463
  • 1
  • 20
  • 29
2

In my @IBDesignable class crashed because I used the custom class for the color and forced unwrapped the colours propertied that's @IBDesignable class found nil while unwrap

So you need to find the IBDesignablesAgent-iOS_[Date]_[YourMac].crash on ~/Library/Logs/DiagnosticReports this location and you will get the reason of the crash with the respected file path.

Now you have to check the respected file.

Tak Rahul
  • 176
  • 7
1

Faced same Error: Had customised UITextField and using interface builder, the error in console was -Use of unimplemented initializer 'init(frame:)' for class "CustomField"

Added the initialiser to fix the error

Avinash
  • 51
  • 3
1

I faced this problem after update to latest XCode version .After trying multiple solution described above ,i only quite Xcode and then shut down system and turn it on and that worked for me .

Mehsam Saeed
  • 235
  • 2
  • 14
1

In my case, I faced this problem because I was using a class that generated that error. Just stop using that and the problem will be solved!

This was the class I was using. I changed for UIView and then the error disappeared:

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Diego Salcedo
  • 83
  • 1
  • 7
  • 1
    For me it was pretty similar to yours Diego but I really need to use the custom UIView class so I just removed the @IBDesignable from it and the errors were gone – NhlanhlaNkosi Oct 07 '22 at 15:31
0

After you make the necessary changes, change the storyboard or in my case a .xib to open in "XCode 7", save and close. This is just a stop gap measure to address the errors but ultimately you will need to fix them or do this until you are no longer able to.

Alberto Lopez
  • 247
  • 4
  • 10
0

In my case, I was using a library which was subclassing UIView. It was using IB_DESIGNABLE, and was missing call to [super awakeFromNib]. Once I've added the call to this method, the bug went away.

I'm not sure if the fact that it was implementing IB_DESIGNABLE had an impact in this.

AnthoPak
  • 4,191
  • 3
  • 23
  • 41
0

This is the easiest way for me: add this script to your Podfile

Podfile:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    next if target.product_type == "com.apple.product-type.bundle"
    target.build_configurations.each do |config|
      config.build_settings['CONFIGURATION_BUILD_DIR'] = '$PODS_CONFIGURATION_BUILD_DIR'
    end
  end
end

Source:

This workaround for @IBDesignable can be found here: https://github.com/CocoaPods/CocoaPods/issues/5334

eNeF
  • 3,241
  • 2
  • 18
  • 41
0

For me it was due to incorrect Font Name in Storyboard. Correcting the font name fixed the issue.

Discarding the below change fixed the issue.

InCorrectFont

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Saif
  • 2,678
  • 2
  • 22
  • 38
  • "–" *looks* like [en dash](https://en.wiktionary.org/wiki/en_dash#Noun) or [em dash](https://en.wiktionary.org/wiki/em_dash#Noun) (not ASCII 45 (0x2D)). Or in other words, caused by copy-pasting from some web page, (Skype) chat, or PDF document. Or is it just the font in use (in the tool/screenshot)? – Peter Mortensen Jun 21 '22 at 14:09
0

I have faced this problem We can use this solution and it's working fine for me

Solution:

  1. Delete the Derived data

    Xcode Preferences -> Location -> Derived Data /Users/YourMacName/Library/Developer/Xcode/DerivedData

  2. Quit Xcode and reopen Xcode.

  3. Clean the build folder. Xcode -> Product -> Clean Build Folder...

Srinivasan_iOS
  • 972
  • 10
  • 12
-1

My first try of exiting Xcode and relaunching helped.

So it is some easy quick-fix instead of some work ,-)

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Karsten
  • 1,869
  • 22
  • 38