what updates are there to attributed string in iOS 26

Asked on 06/24/2025

1 search

In iOS 26, there are several updates to the AttributedString:

  1. Natural Selection: A new property called selectedRanges has been introduced to represent an array of non-contiguous NS ranges, replacing the single selectedRange property. This allows for more accurate text selection, especially in bidirectional text scenarios. The UITextViewDelegate and UITextViewDelegate protocols have been updated to accept an array of NS ranges instead of a single range. This change ensures that actions relying on text selection, like deleting text, operate on the correct text ranges. For more details, you can refer to the session Enhance your app’s multilingual experience.

  2. SwiftUI Rich Text Editor: The SwiftUI text editor now supports AttributedString, allowing for rich text editing. You can customize paragraph styles, transform attributes, and constrain attributes that users can apply in your app. This is particularly useful for creating rich text experiences in SwiftUI. For more information, see the session Code-along: Cook up a rich text experience in SwiftUI with AttributedString.

  3. Transform Function: AttributedString provides a transform function that takes a range or an array of ranges and a closure to mutate the AttributedString in place. This function updates the provided range with new indices to ensure correct usage in the resulting AttributedString. This is useful for maintaining the integrity of text selections and indices when the text content changes. More details can be found in the session Code-along: Cook up a rich text experience in SwiftUI with AttributedString.

These updates enhance the flexibility and functionality of AttributedString in iOS 26, particularly in the context of text editing and selection.