The situation and steps to reliably reproduce:
- Set up a macOS app project with Swift and storyboards for UI in Xcode.
- Define an arbitrary color for the "AccentColor" color set in the asset catalogue which is there by default in the Xcode project template.
- Create a
@IBDesignablesubclass ofNSView(see source code here or further below). - Add a custom view from the Xcode library to the default window in the storyboard and set its class to whatever the custom class is named (
DesignableViewin my example case). - Set the
@IBDesignablecolor property to "AccentColor" in the attributes inspector of Xcode. - Either refresh the previews manually (see Editor menu of Xcode) or wait for the automatic refresh.
You can find the example project in this GitHub repository. The view in question is quite simple (source code copied to here by request):
import AppKit
@IBDesignable class DesignableView: NSView {
@IBInspectable var color: NSColor = .clear
}
Observations:
- It works fine with system colors.
- Picking color sets from the asset catalogue also is not a problem in case of predefined views.
Problem:
As soon as I pick a color from the asset catalogue (in this case "AccentColor" but the name does not matter), the custom view preview in the storyboard crashes with the following error:
The agent raised a "NSInvalidUnarchiveOperationException" exception: *** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (IBICDynamicCocoaColor) for key (NSColor) because no class named "IBICDynamicCocoaColor" was found; the class needs to be defined in source code or linked in from a library (ensure the class is part of the correct target). If the class was renamed, use setClassName:forClass: to add a class translation mapping to NSKeyedUnarchiver
How can I fix that? The error message does not help me.
