Xcode 8 - IB Designables - Failed to render and update auto layout status, The agent crashed
Asked Answered
C

24

190

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.

Caulis answered 27/9, 2016 at 18:54 Comment(4)
Maybe check the repository for the Pod you're using and see if this issue is prevalent among other users?Bobcat
Any relevant answer to this?Oilcloth
did you guys find any workaround ?Translatable
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.Theism
S
205

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.

Swipe answered 8/3, 2017 at 18:15 Comment(13)
But my problem is that it only happens sometimes for the same storyboard.Cana
Exactly, It happened sometimes in my projects.Educative
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:).Basion
@YevhenDubinin Thank you, this helped me. Everything was fine after I implemented init(frame:) in my UIButton subclassBihar
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.Mafalda
This fixed my issue, But I had to quit xCode before deleting derived dataCedilla
I fixed this problem by rebooting mac.Stereochrome
the best answer init(frame:) is common issueRalline
Quit xcode and clear DerivedData. It solved the issue.Blacken
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.Closure
looking for the IBDesignablesAgentCocoaTouch logs saved me! Thank you very much!Inure
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?Anlage
@Anlage just add a default non nil color like UIColor.black. this will just satisfy IB, runtime will work just fineHasheem
P
102

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.

Pilgrimage answered 6/3, 2018 at 6:4 Comment(5)
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.Adlare
Refresh all views for the win for me as well. Thanks!Lathan
Second time your answer has saved meEarthly
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).Heathenize
How is this still a problem since the question has been asked in 2016? This answer along with the accepted answer appears to solve this XCode problem.Teleview
S
61

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.

Stank answered 6/6, 2018 at 8:58 Comment(2)
Its ridiculous but it Worked.Hopefully
Who knows it could be the answer. It worked I still can't believeTallage
V
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

Vasileior answered 17/4, 2018 at 8:11 Comment(4)
100% true. downgrade to 1.4.0 resolved the issue for me.Mokpo
Worked, 1.5.0 pods.Beckerman
its work for me, you should add end` to last of code.Blather
Worked for me as well. Tried all other suggestions with no success. Tested with Pods 1.3.1Brede
B
19

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

override init(frame: CGRect) {
    super.init(frame: frame)
}
Biramous answered 31/8, 2018 at 6:58 Comment(2)
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.Electrode
Thanks! Good answer )Cotonou
A
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)
Aconite answered 14/5, 2019 at 10:33 Comment(0)
H
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

Haggai answered 10/4, 2019 at 13:51 Comment(3)
The app is actual Console rather than Terminal just as an FYI.Compensable
Good catch! Edited my answer.Haggai
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.Coracoid
S
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.

Seleta answered 3/8, 2017 at 5:36 Comment(1)
What do you mean by "deside"? Do you mean "inside"? Or something else? Please respond by editing (changing) your answer, not here in comments (without "Edit:", "Update:", or similar - the answer should appear as if it was written today).Kohl
L
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.

Labors answered 30/6, 2017 at 13:45 Comment(0)
B
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

Bainbrudge answered 21/2, 2020 at 15:26 Comment(2)
Using Console was what helped me solve my problem. Much more detailed messages than what was in Xcode.Dismal
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! :DExternality
H
6

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

But Close and reopened the project did.

Hebbe answered 11/1, 2019 at 10:8 Comment(0)
N
4

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

Neurogram answered 13/4, 2018 at 6:56 Comment(0)
P
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.

Proximate answered 12/10, 2018 at 18:46 Comment(1)
As its documentation says, don't forget to call super.prepareForInterfaceBuilder() in your implementation of prepareForInterfaceBuilder().Actuality
P
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
Pedate answered 12/5, 2017 at 6:11 Comment(6)
Could you elaborate on how this actually solves the problem?Cluff
this solved the issue but still dont know why uncoment that use_frameworks because thats for swift project rightDepreciate
My Podfile is already using frameworks, any suggestions past uncommenting that?Molloy
@moni15 i added one more possible solution. Please check.Pedate
Uncommenting #use_frameworks in pod file and clearing the DerivedData worked for me.Seedling
previously it was use_frameworks in pod file, i changed that to #use_frameworks, then the error went away :)Abscissa
B
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.

Backgammon answered 24/11, 2020 at 8:4 Comment(0)
A
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

Aundreaaunson answered 25/6, 2019 at 17:44 Comment(0)
R
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 .

Router answered 26/7, 2019 at 6:45 Comment(0)
K
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

Knowitall answered 12/2, 2021 at 18:11 Comment(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 goneDollarfish
M
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.

Miscarriage answered 9/3, 2017 at 18:20 Comment(0)
U
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.

Underlet answered 3/4, 2018 at 10:7 Comment(1)
Where did you add the code for [super awakeFromNib]? Can you share your code?Overage
S
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

Spree answered 26/4, 2020 at 9:52 Comment(0)
A
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

Acarid answered 21/9, 2021 at 6:4 Comment(1)
"–" looks like en dash or em dash (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)?Kohl
L
0

I have faced this problem We can use this solution and it's worked 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...

Lombard answered 30/6, 2023 at 12:17 Comment(0)
E
-1

My first try of exiting Xcode and relaunching helped.

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

Empurple answered 18/11, 2021 at 13:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.