Protocol
AttributedStringProtocol
iOS 15.0+
iPadOS 15.0+
Mac Catalyst 15.0+
macOS 12.0+
tvOS 15.0+
watchOS 8.0+
A protocol that provides common functionality to attributed strings and attributed substrings.
@dynamicMemberLookup protocol AttributedStringProtocol : AttributedStringAttributeMutation, CustomStringConvertible, Hashable, Sendable
Overview
Don’t declare new conformances to AttributedStringProtocol. Only the AttributedString and AttributedSubstring types in the standard library are valid conforming types.
Topics
Instance Properties
var characters: AttributedString.CharacterViewThe characters of the attributed string, as a view into the underlying string.var endIndex: AttributedString.IndexA string’s past-the-end position — the position one greater than the last valid subscript argument.var runs: AttributedString.RunsThe attributed runs of the attributed string, as a view into the underlying string.var startIndex: AttributedString.IndexThe position of the first character in a nonempty attributed string.var unicodeScalars: AttributedString.UnicodeScalarViewThe Unicode scalars of the attributed string, as a view into the underlying string.var utf16: AttributedString.UTF16Viewvar utf8: AttributedString.UTF8View
Instance Methods
func index(AttributedString.Index, offsetByCharacters: Int) -> AttributedString.IndexReturns the position of the character offset a given distance, measured in characters, from a given string index.func index(AttributedString.Index, offsetByRuns: Int) -> AttributedString.IndexReturns the position of the run offset a given number of runs from a given string index.func index(AttributedString.Index, offsetByUnicodeScalars: Int) -> AttributedString.IndexReturns the position of the Unicode scalar offset a given distance, measured in Unicode scalars, from a given string index.func index(afterCharacter: AttributedString.Index) -> AttributedString.IndexReturns the position of the character immediately after another charcter indicated by an index.func index(afterRun: AttributedString.Index) -> AttributedString.IndexReturns the position of the run immediately after a run indicated by an index.func index(afterUnicodeScalar: AttributedString.Index) -> AttributedString.IndexReturns the position of the Unicode scalar immediately after a Unicode scalar indicated by an index.func index(beforeCharacter: AttributedString.Index) -> AttributedString.IndexReturns the position of the character immediately before another charcter indicated by an index.func index(beforeRun: AttributedString.Index) -> AttributedString.IndexReturns the position of the run immediately before a run indicated by an index.func index(beforeUnicodeScalar: AttributedString.Index) -> AttributedString.IndexReturns the position of the Unicode scalar immediately before a Unicode scalar indicated by an index.func mergingAttributes(AttributeContainer, mergePolicy: AttributedString.AttributeMergePolicy) -> AttributedStringReturns an attributed string by merging the attributed string’s attributes with those in a specified attribute container.func range<T>(of: T, options: String.CompareOptions, locale: Locale?) -> Range<AttributedString.Index>?Returns the range of a substring in the attributed string, if it exists.func replacingAttributes(AttributeContainer, with: AttributeContainer) -> AttributedStringReturns an attributed string by replacing occurrences of attributes in one attribute container with those in another attribute container.func settingAttributes(AttributeContainer) -> AttributedStringReturns an attributed string by setting the attributed string’s attributes to those in a specified attribute container.
Subscripts
subscript(_:)Returns an attribute value that corresponds to an attributed string key.subscript(dynamicMember:)Returns an attribute value that a key path indicates.
Default Implementations
Relationships
Inherits From
AttributedStringAttributeMutationSwift.CustomStringConvertibleSwift.EquatableSwift.HashableSwift.SendableSwift.SendableMetatype