Manage text storage and perform custom layout of text-based content in your app's views using TextKit.

Posts under TextKit tag

165 Posts

Post

Replies

Boosts

Views

Activity

NSInternalInconsistencyException
We are facing the below crash quite for some days, With key NSInternalInconsistencyException, after our users got updated their OS to iOS 15, for earlier versions it works fine without any crash. We are clueless as nothing in the stack call our native code and each line in the stack relates to UI. this issue is happening for most of our users repeatedly, we tried various scenarios but unable to find the root cause. Similar issues have found in the forum when upgrading from iOS 12 to 13 but they related to threading issues, this is of a kind range exception, please do the needful. Appreciate your help in advance. Fatal Exception: NSInternalInconsistencyException out of bounds characterRange {0, 0} specified to _drawTexCorrectionMarker:characterRange:atOrigin:graphicsContext: Fatal Exception: NSInternalInconsistencyException 0 CoreFoundation 0x9905c __exceptionPreprocess 1 libobjc.A.dylib 0x15f54 objc_exception_throw 2 Foundation 0x13099c _userInfoForFileAndLine 3 UIFoundation 0xa933c -[NSTextLineFragment _drawTexCorrectionMarker:characterRange:atOrigin:graphicsContext:] 4 UIFoundation 0x8b08 -[NSTextLineFragment drawTextCorrectionMarkersAtPoint:graphicsContext:] 5 UIFoundation 0x65c44 -[NSTextLineFragment drawAtPoint:graphicsContext:] 6 UIFoundation 0x69ef4 -[NSTextLineFragment drawAtPoint:inContext:] 7 UIFoundation 0x3eb80 -[NSTextLayoutFragment drawAtPoint:inContext:] 8 UIKitCore 0x649ce4 _UITextCanvasDrawWithFadedEdgesInContext 9 UIKitCore 0x77cb4c -[_UITextLayoutFragmentView drawRect:] 10 UIKitCore 0x188930 -[UIView(CALayerDelegate) drawLayer:inContext:] 11 QuartzCore 0x4d2c8 CABackingStoreUpdate_ 12 QuartzCore 0x8fe60 invocation function for block in CA::Layer::display_() 13 QuartzCore 0x91ae0 -[CALayer _display] 14 QuartzCore 0x31bc4 CA::Layer::layout_and_display_if_needed(CA::Transaction*) 15 QuartzCore 0x460b0 CA::Context::commit_transaction(CA::Transaction*, double, double*) 16 QuartzCore 0x4f174 CA::Transaction::commit() 17 QuartzCore 0x3121c CA::Transaction::flush_as_runloop_observer(bool) 18 UIKitCore 0x544c28 _UIApplicationFlushCATransaction 19 UIKitCore 0x7dead8 _UIUpdateSequenceRun 20 UIKitCore 0xe56294 schedulerStepScheduledMainSection 21 UIKitCore 0xe55760 runloopSourceCallback 22 CoreFoundation 0xbb030 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ 23 CoreFoundation 0xcbcf0 __CFRunLoopDoSource0 24 CoreFoundation 0x5ff8 __CFRunLoopDoSources0 25 CoreFoundation 0xb804 __CFRunLoopRun 26 CoreFoundation 0x1f3c8 CFRunLoopRunSpecific 27 GraphicsServices 0x138c GSEventRunModal 28 UIKitCore 0x51b060 -[UIApplication _run] 29 UIKitCore 0x298b8c UIApplicationMain 30 mobilex 0x41673c (Missing) 31 User Mobile 0x25f18 main + 43 (main.m:43) 32 ??? 0x1056f9a24 (Missing)
7
1
4.7k
Dec ’21
NSLayoutManager.drawGlyphs() can not display MarkDown attributed string
We use NSLayoutManager/NSTextStorage/NSTextContainer to display markdown attributed string on a canvas. MarkDown string was processed properly, but NSLayoutManager just exhibits the plain text. The code is as follows:     var layoutmanager = NSLayoutManager()     var textstorage = NSTextStorage()     var textcontainer = NSTextContainer()   var attrStr = try AttributedString.init(markdown: "**test**", options: AttributedString.MarkdownParsingOptions(interpretedSyntax: .inlineOnlyPreservingWhitespace)) var attrString = NSMutableAttributedString(attrStr)  self.textstorage.setAttributedString(attrString!) // draw text layout     let range = self.layoutmanager.glyphRange(for: self.textcontainer)     self.layoutmanager.drawBackground(forGlyphRange: range, at: self.textLocation)     self.layoutmanager.drawGlyphs(forGlyphRange: range, at: self.textLocation) Is it because TextKit 1 does not support markdown string display or I miss something else ? Any help will be appreciated. Thanks!
1
0
1.6k
Nov ’21
Adding un-selectable text to NSTextParagraph?
I want to add characters to the display of my paragraphs without modifying the underlying text storage. To be concrete, let's say that I want to prefix each paragraph with "Whereas, ". Further, when I drag out a text selection on a paragraph that's displayed this way, I do not want "Whereas, " to receive a selection highlight. Using TextKit 2, it's pretty easy to accomplish the first part using a NSTextContentStorageDelegate whose method textContentStorage(_: NSTextContentStorage, textParagraphWith: NSRange) -> NSTextParagraph? adds my prefix to each paragraph. I modified the WWDC21 demo program to do it. I appreciate how I can avoid glyph munging by using TextKit 2 instead of TextKit 1, it will save a lot of trouble. If I drag a selection across the prefix, then it receives the selection highlight. What's more, when I drag a selection across the end of the paragraph, the last eight characters (and, I presume, the invisible newline) do not receive the selection highlight. So adding the prefix has skewed the selection indices. It seems to me that the TextKit 2 designers may intend for me to use a NSTextLocation subclass consisting of a "storage" index and a "display" sub-index. On the storage indices there are the characters of the text storage, and at (storage index, display sub-index)-pairs are the characters of my prefix. While the user drags out a selection, I should subtract from the NSTextSelection any NSTextRanges belonging to non-storage text such as my prefix. Am I on the right track, so far?
0
0
1k
Nov ’21
NSInternalInconsistencyException
We are facing the below crash quite for some days, With key NSInternalInconsistencyException, after our users got updated their OS to iOS 15, for earlier versions it works fine without any crash. We are clueless as nothing in the stack call our native code and each line in the stack relates to UI. this issue is happening for most of our users repeatedly, we tried various scenarios but unable to find the root cause. Similar issues have found in the forum when upgrading from iOS 12 to 13 but they related to threading issues, this is of a kind range exception, please do the needful. Appreciate your help in advance. Fatal Exception: NSInternalInconsistencyException out of bounds characterRange {0, 0} specified to _drawTexCorrectionMarker:characterRange:atOrigin:graphicsContext: Fatal Exception: NSInternalInconsistencyException 0 CoreFoundation 0x9905c __exceptionPreprocess 1 libobjc.A.dylib 0x15f54 objc_exception_throw 2 Foundation 0x13099c _userInfoForFileAndLine 3 UIFoundation 0xa933c -[NSTextLineFragment _drawTexCorrectionMarker:characterRange:atOrigin:graphicsContext:] 4 UIFoundation 0x8b08 -[NSTextLineFragment drawTextCorrectionMarkersAtPoint:graphicsContext:] 5 UIFoundation 0x65c44 -[NSTextLineFragment drawAtPoint:graphicsContext:] 6 UIFoundation 0x69ef4 -[NSTextLineFragment drawAtPoint:inContext:] 7 UIFoundation 0x3eb80 -[NSTextLayoutFragment drawAtPoint:inContext:] 8 UIKitCore 0x649ce4 _UITextCanvasDrawWithFadedEdgesInContext 9 UIKitCore 0x77cb4c -[_UITextLayoutFragmentView drawRect:] 10 UIKitCore 0x188930 -[UIView(CALayerDelegate) drawLayer:inContext:] 11 QuartzCore 0x4d2c8 CABackingStoreUpdate_ 12 QuartzCore 0x8fe60 invocation function for block in CA::Layer::display_() 13 QuartzCore 0x91ae0 -[CALayer _display] 14 QuartzCore 0x31bc4 CA::Layer::layout_and_display_if_needed(CA::Transaction*) 15 QuartzCore 0x460b0 CA::Context::commit_transaction(CA::Transaction*, double, double*) 16 QuartzCore 0x4f174 CA::Transaction::commit() 17 QuartzCore 0x3121c CA::Transaction::flush_as_runloop_observer(bool) 18 UIKitCore 0x544c28 _UIApplicationFlushCATransaction 19 UIKitCore 0x7dead8 _UIUpdateSequenceRun 20 UIKitCore 0xe56294 schedulerStepScheduledMainSection 21 UIKitCore 0xe55760 runloopSourceCallback 22 CoreFoundation 0xbb030 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ 23 CoreFoundation 0xcbcf0 __CFRunLoopDoSource0 24 CoreFoundation 0x5ff8 __CFRunLoopDoSources0 25 CoreFoundation 0xb804 __CFRunLoopRun 26 CoreFoundation 0x1f3c8 CFRunLoopRunSpecific 27 GraphicsServices 0x138c GSEventRunModal 28 UIKitCore 0x51b060 -[UIApplication _run] 29 UIKitCore 0x298b8c UIApplicationMain 30 mobilex 0x41673c (Missing) 31 User Mobile 0x25f18 main + 43 (main.m:43) 32 ??? 0x1056f9a24 (Missing)
Replies
7
Boosts
1
Views
4.7k
Activity
Dec ’21
NSLayoutManager.drawGlyphs() can not display MarkDown attributed string
We use NSLayoutManager/NSTextStorage/NSTextContainer to display markdown attributed string on a canvas. MarkDown string was processed properly, but NSLayoutManager just exhibits the plain text. The code is as follows:     var layoutmanager = NSLayoutManager()     var textstorage = NSTextStorage()     var textcontainer = NSTextContainer()   var attrStr = try AttributedString.init(markdown: "**test**", options: AttributedString.MarkdownParsingOptions(interpretedSyntax: .inlineOnlyPreservingWhitespace)) var attrString = NSMutableAttributedString(attrStr)  self.textstorage.setAttributedString(attrString!) // draw text layout     let range = self.layoutmanager.glyphRange(for: self.textcontainer)     self.layoutmanager.drawBackground(forGlyphRange: range, at: self.textLocation)     self.layoutmanager.drawGlyphs(forGlyphRange: range, at: self.textLocation) Is it because TextKit 1 does not support markdown string display or I miss something else ? Any help will be appreciated. Thanks!
Replies
1
Boosts
0
Views
1.6k
Activity
Nov ’21
TextKit 2 documentation update?
The documentation for TextKit 2 is a bit thin. I have a few questions about that: Is more complete documentation available to Developer Program members? When can developers expect for the API documentation to be updated? When will overview documentation, like TextKit 1 has, be available?
Replies
0
Boosts
0
Views
1k
Activity
Nov ’21
Adding un-selectable text to NSTextParagraph?
I want to add characters to the display of my paragraphs without modifying the underlying text storage. To be concrete, let's say that I want to prefix each paragraph with "Whereas, ". Further, when I drag out a text selection on a paragraph that's displayed this way, I do not want "Whereas, " to receive a selection highlight. Using TextKit 2, it's pretty easy to accomplish the first part using a NSTextContentStorageDelegate whose method textContentStorage(_: NSTextContentStorage, textParagraphWith: NSRange) -> NSTextParagraph? adds my prefix to each paragraph. I modified the WWDC21 demo program to do it. I appreciate how I can avoid glyph munging by using TextKit 2 instead of TextKit 1, it will save a lot of trouble. If I drag a selection across the prefix, then it receives the selection highlight. What's more, when I drag a selection across the end of the paragraph, the last eight characters (and, I presume, the invisible newline) do not receive the selection highlight. So adding the prefix has skewed the selection indices. It seems to me that the TextKit 2 designers may intend for me to use a NSTextLocation subclass consisting of a "storage" index and a "display" sub-index. On the storage indices there are the characters of the text storage, and at (storage index, display sub-index)-pairs are the characters of my prefix. While the user drags out a selection, I should subtract from the NSTextSelection any NSTextRanges belonging to non-storage text such as my prefix. Am I on the right track, so far?
Replies
0
Boosts
0
Views
1k
Activity
Nov ’21