Is there a limit to the string size that a SwiftUI Text view can display in iOS?


I’m working on an app that will generate a list of anagrams from a set of input letters. (among other things.)

It’s a Multiplatform SwiftUI app.

I just discovered that when running on the iOS 15 simulator, the Text field that displays the resulting list of anagram words “blanks out” and fails to display the list of words when the length of the text gets too long (somewhere around 128,575 characters.)

Granted this is an edge case, but I found the problem when generating anagrams from the string “The quick brown fox jumps over the lazy dog”, something a user might do.

The results are quite similar when running on my iPhone 15 pro (with the thresholds being slightly different.) Both the sim and the phone are running iOS 17.x. (The sim is iOS 17.0, the phone is running 17.1.2)

The same app doesn’t have this problem when build as a Mac app. (or at least I haven’t found it.)

The threshold where the text view shows nothing seems to vary slightly, and also depend on the text being displayed. If I sort the list of words longest to shortest, it might fail to show its contents, and if I instead sort the list shortest to longest, it is able to display. That makes me think it has to to with word wrapping and the size of the Text view in it’s ScrollView, but I’m really not sure.

The text is wrapped in a ScrollView, and tied to an @Pubished variable from a state object for the Anagrams view:

                        ScrollView() {
                            Text(anagramsState.wordList)
                                .lineLimit(nil)
                                .multilineTextAlignment(.leading)
                                .frame(minWidth: geometry.size.width - 2, minHeight: 20, alignment: .topLeading)
                        }

I don’t know if it’s a memory issue, a rectangle size overflow, or something else.

It’s a bit hard to post a minimal reproducible example since this is an app I am planning to sell. I’ll have to work on that.

Are any of you aware of the limits on how much text a SwiftUI Text field can display on iOS devices?

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img