Instance MethodFoundationEssentials
transform(updating:body:)
iOS 26.0+
iPadOS 26.0+
Mac Catalyst 26.0+
macOS 26.0+
tvOS 26.0+
visionOS 26.0+
watchOS 26.0+
Tracks the location of the provided range throughout the mutation closure, updating the provided range to one that represents the same effective locations after the mutation.
mutating func transform<E>(updating range: inout Range<AttributedString.Index>, body: (inout AttributedString) throws(E) -> Void) throws(E) where E : Error
Parameters
rangeA range to track throughout the
bodyclosure.bodyA mutating operation, or set of operations, to perform on the value of
self. The value ofselfis provided to the closure as aninout AttributedStringthat the closure should mutate directly. Do not capture the value ofselfin the provided closure - the closure should mutate the providedinoutcopy.
Discussion
If updating the provided range is not possible (tracking failed) then this function will fatal error. Use the Optional-returning variants to provide custom fallback behavior.