Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assert Current fallback trait collection contains one or more unspecified traits:

Tags:

ios13

xcode11

Once our app is run on iOS13 then the log is full of wried assertions. Anybody some tips how to remove it?

2019-09-19 08:05:43.528382+0200 Ts-2-cz-test[56066:20590106] [Assert] Current fallback trait collection contains one or more unspecified traits: {(
    "_UITraitNameDisplayScale",
    "_UITraitNameDisplayCornerRadius",
    "_UITraitNameSemanticContext",
    "_UITraitNameUserInterfaceLevel",
    "_UITraitNamePresentationSemanticContext",
    "_UITraitNameVibrancy",
    "_UITraitNameDisplayGamut",
    "_UITraitNameDebugHighlight",
    "_UITraitNamePreferredContentSizeCategory",
    "_UITraitNameTouchLevel",
    "_UITraitNameAccessibilityContrast",
    "_UITraitNameLegibilityWeight"
)}; traitCollection: <UITraitCollection: 0x7fb4ce32ad20; HorizontalSizeClass = Compact>; currentFallbackEnvironment: <UIView: 0x7fb46c421d80; frame = (0 0; 1024 1366); autoresize = W+H; layer = <CALayer: 0x7fb46c421ef0>>
like image 511
Jan Loose Avatar asked Sep 19 '19 06:09

Jan Loose


2 Answers

I had the same issue here because I was overriding the traitCollection property (which is not recommended by Apple but I didn't find any other solution in my case) and the new traitCollection I returned has many unspecified traits (as the error message said).

So now I return a new traitCollection object but I initialize it by adding super.traitCollection. So in my view controller I have something like:

public override var traitCollection: UITraitCollection {
    var newTraitCollection: [UITraitCollection] = [super.traitCollection]
    // I need to force size class on iPad
    if UIDevice.current.userInterfaceIdiom == .pad {
        newTraitCollection += [UITraitCollection(verticalSizeClass: .regular), UITraitCollection(horizontalSizeClass: .compact)]
    }
    return UITraitCollection(traitsFrom: newTraitCollection)
}
like image 165
Y.Bonafons Avatar answered Jan 22 '23 13:01

Y.Bonafons


UITraitCollection has change in iOS13. U can find out where this class has been used.

eg: remove this method [UITraitCollection traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassUnspecified]

like image 37
Simon Hu Avatar answered Jan 22 '23 12:01

Simon Hu