iOSのドキュメントには次のように書かれていますが:
NLayoutManager、NSTextStorage、および NSTextContainer は、アプリが単一のスレッドからのアクセスを保証している限り、サブスレッドからアクセスできます。
私は時々この例外に遭遇しました:
キャッチされていない例外 'NSInternalInconsistencyException' が原因でアプリを終了しています。理由: 'メイン スレッドでのみ実行してください!'
バックトレースは次のとおりです。
Exception Type: SIGABRT
Exception Codes: #0 at 0x197bca58c
Crashed Thread: 7
Application Specific Information:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Only run on the main thread!'
Last Exception Backtrace:
0 CoreFoundation 0x000000018afd2f50 __exceptionPreprocess + 132
1 libobjc.A.dylib 0x00000001974dc1fc objc_exception_throw + 56
2 CoreFoundation 0x000000018afd2e10 +[NSException raise:format:arguments:] + 112
3 Foundation 0x000000018bb0ae20 -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 84
4 UIFoundation 0x00000001940f0654 -[NSLayoutManager(NSPrivate) _resizeTextViewForTextContainer:] + 412
5 UIFoundation 0x00000001940f0318 -[NSLayoutManager(NSPrivate) _recalculateUsageForTextContainerAtIndex:] + 1748
6 UIFoundation 0x000000019411ec2c _enableTextViewResizing + 236
7 UIFoundation 0x0000000194123e18 -[NSLayoutManager textContainerForGlyphAtIndex:effectiveRange:] + 484
8 UIFoundation 0x0000000194125c60 -[NSLayoutManager glyphRangeForTextContainer:] + 352
注意すべきことの 1 つは、 myNLayoutManager
がUITextView
. UITextView
バックグラウンド スレッドでテキスト レイアウトを行うために使用される通常の方法と考えることができます。
つまり、ドキュメントの内容に反してNLayoutManager
、単一のバックグラウンド スレッドにアタッチされている場合、安全に使用できないということUITextView
ですか?