10

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>>
Jan Loose
  • 103
  • 4

3 Answers3

21

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)
}
shim
  • 9,289
  • 12
  • 69
  • 108
Y.Bonafons
  • 2,329
  • 13
  • 20
1

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

eg: remove this method [UITraitCollection traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassUnspecified]

Simon Hu
  • 23
  • 5
0

The selected answer still give me errors. Instead you should use @NSCopying var overrideTraitCollection: UITraitCollection? { get set }

See more here

Rindom
  • 41
  • 4