Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Color Sets and UIColorAttributeTraitStorage error

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?

like image 213
Maria Scanavie Avatar asked Sep 26 '17 15:09

Maria Scanavie


2 Answers

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.

enter image description here

like image 170
hungrxyz Avatar answered Sep 18 '22 09:09

hungrxyz


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'

enter image description here

enter image description here

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.

like image 24
Groot Avatar answered Sep 21 '22 09:09

Groot