I've been trying to make an app written in Xcode 9 for iOS11 iOS9.0-compatible and all of a sudden it crashed with this error on iPhone 4S:
*** Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named _UIColorAttributeTraitStorage'
Same project runs fine on iPhone 7.
I've changed all [UIColor colorNamed:] as Xcode suggests:
if (@available(iOS 11.0, *)) {
statusBar.backgroundColor = [UIColor colorNamed:@"MyColor"];
} else {
statusBar.backgroundColor = kColorFromHex(0x509E2F);
}
But the error didn't go anywhere. I also didn't find any mention of UIColorAttributeTraitStorage in Apple Documentation or anywhere on the web except some japanese(?) post. All I understood from this post is that someone probably faced the same issue with Color Set in iOS 10.3 and Xcode 9.
So it seems the problem is in xcassets containing Color Sets. Does this mean there is no backwards compatibility for Color Sets? And that if I add one there's no way to distribute my app for iOS lower than 11.0?
P.S.: I don't have any iOS 10 device, so I don't know if the issue is still there for 10+ since Xcode 9 public release. Can anyone give it a try?
I encountered the same issue when using the new Color sets in Xcode 9 Interface Builder. If you need to support iOS 10 or earlier, don't use any color from Color set in Interface Builder.
So just make sure you don't select any colors above iPhoneSDK
section in Interface Builder.
TL;DR; You may have selected a color from the "Recently Used Color" dropdown that is a defined Color Asset in an other project than the one you are currently using. Make sure that you don't have any selected color in a nib or storyboard that is marked as Missing.
Say that you in "project 1" define a Color Asset and you name it something e.g. "YorkGreen" as in the example below.
That color will show up in the "Recently Used Colors" dropdown for all other project. And if you select it (from any other project than "project 1") an NSInvalidUnarchiveOperationException
will be thrown when loading that view (nib or storyboard) and your app will crash.
Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException',
reason: 'Could not instantiate class named _UIColorAttributeTraitStorage'
Hopefully it's a bug that Xcode 9 even show Color Assets from other projects and that this will be fixed in a future release of Xcode.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With