The code has been working for serval years. now it crashes when running on iOS 16.2 beta1 & beta2
UITextView *text = [[UITextView alloc] init];
text.attributedText = attributedText;
text.frame = CGRectZero;
text.editable = NO;
text.scrollEnabled = NO;
text.clipsToBounds = NO;
text.showsVerticalScrollIndicator = NO;
text.showsHorizontalScrollIndicator = NO;
text.textContainer.lineFragmentPadding = 0;
text.textContainerInset = UIEdgeInsetsZero;
text.contentInset = UIEdgeInsetsZero;
text.tag = index;
[self addSubview:text];
crash log
Last Exception Backtrace:
0 CoreFoundation 0x1b9849e88 __exceptionPreprocess + 164
1 libobjc.A.dylib 0x1b2b5b8d8 objc_exception_throw + 60
2 CoreFoundation 0x1b9939c58 __CFDictionaryCreateGeneric + 0
3 UIFoundation 0x1c3c937f4 -[NSCountableTextLocation compare:] + 204
4 UIFoundation 0x1c3d0d3fc -[NSTextRange textRangeByIntersectingWithTextRange:] + 144
the system is upgraded to iPhone OS 16.2 (20C5043e) from iPhone OS 16.2 (20C5032e) ,it also crash
Guess it may be caused by the upgrade from TextKit1 to TextKit2.
// To ensure compatibility with older code, accessing the .layoutManager of a UITextView - or its .textContainer's .layoutManager - will cause a UITextView that's using TextKit 2 to 'fall back' to TextKit 1, and return a newly created NSLayoutManager. After this happens, .textLayoutManager will return nil - and _any TextKit 2 objects you may have cached will cease functioning_. Be careful about this if you are intending to be using TextKit 2!
@property(nonatomic, readonly) NSLayoutManager *layoutManager API_AVAILABLE(ios(7.0));
then call layoutManager,'fall back' to TextKit 1, it work!
can I ask the question,What is the cause of the problem? can it be fixed on the 16.2 beta3 or release version?
Thank you very much!