Colors.xcassets isn't loaded in the Interface Builder runtime

Originator:xlo
Number:rdar://41244137 Date Originated:June 19 2018
Status:Dupe Resolved:
Product:Xcode Product Version:9.4.1
Classification:Bug Reproducible:always
 
Summary:
We’re using the new Colors.xcassets catalog and are quite happy with it.
Now, there is an issue when using custom views in Interface Builder

Consider a view like this:

class CustomView: UIView {
    init() {
        self.backgroundColor = UIColor(named: “primaryColor”)!
    }
}

This will crash when used in Interface Builder, because the Colors.xcassets file doesn’t seem to be available and the force unwrap will fail. On devices and in the Simulator this works just fine.

Steps to Reproduce:
1. Create a custom view like above
2. Use it in Interface Builder

Expected Results:
The View should have the background color loaded from the Colors.xcassets catalog

Actual Results:
“IB Designables: Failed to render and update auto layout status for MyViewController (07s-PO-QA4): The agent crashed”


Version:
9.4.1

Notes:
See also this stack overflow question: https://stackoverflow.com/questions/50851953/named-colors-crash-in-interface-builder-builds

Comments

Seems to also crash on images :(


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!