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 kn
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.
Just simple put your code in main thread of UI update :
DispatchQueue.main.async
{
// Put your code here
}
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 { }
.