Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

returned nil from -traitCollection, which is not allowed in Xcode 11 Beta

Tags:

xcode

ios

swift

Assertion failure in UITraitCollection * _Nonnull returned nil from -traitCollection, which is not allowed? when I try to run Xcode 11 beta in ios 13 it crashed. I don't know what was wrong.

like image 850
NemSothea Avatar asked Sep 16 '19 02:09

NemSothea


2 Answers

[super init]

I ran across this problem because one of the unnamed previous coders on my codebase, whom I frequently curse, didn't call [super init] on a class that implements the UITraitEnvironment (aka UIView or UIViewController)!

If I could wield a battle hammer backwards five years in time, I would.

This implementation in a subclass of UIViewController

- (id)initWithStartPositionPdf:(float)startPosition withScrollViewHeight:(float)scrollViewHeight {
    _startPosition = startPosition;
    _scrollViewHeight = scrollViewHeight;

    self.isPdfView = YES;

    return self;
}

was updated to…

- (instancetype)initWithStartPositionPdf:(float)startPosition withScrollViewHeight:(float)scrollViewHeight {
    self = [super initWithNibName:nil bundle:nil];
    _startPosition = startPosition;
    _scrollViewHeight = scrollViewHeight;
    _isPdfView = YES;
    return self;
}

and resolved the crash I started receiving in Xcode 11 / iOS 13.

like image 92
bshirley Avatar answered Sep 30 '22 05:09

bshirley


This is how iOS 13 and Xcode 11 deal with the main thread checker inconsistencies.

basically, you are updating the UI from a background thread. Just make sure you're updating all your UI in the main thread.

Simply wrap the code that updates your UI inside DispatchQueue.main.async { }.

like image 38
kalamoni Avatar answered Sep 30 '22 04:09

kalamoni