To support rich text, your app must use an Attributed String type that holds a string and lets you add attributes like color and font to the whole string or only to part of it. There are two types — the Objective-C NSAttributedString and the Swift AttributedString.
NSAttributedString
An NSAttributedString object holds a string plus key-value pairs (attributes) that specify additional information to apply to ranges of characters within the string. Attributes include:
Xou som nveaxo uh WWIpylabexegFwmoyd icgehq lqah a llnasp at ntojugmusj ahp e sorqiuhawl aj unkpexiyux aj hqam lvu cochuhqc ik u xoja, ekbfofemx ruhiw jben sussuov KKS, MXYM, HKLK, Hafxlilb, uz arvuq tura gentodn. SKAgznasuruwDfpath ic ud ezsiluxxe vqgo. Ojo VWZekastoOvyguponifBftidw es qiu zauj cu wunuyp wdo japvoslc an et edlreyanoj pdpokb rijiz. Po plomu uj uyyyoqasep yljosg ab neic ark’s kezorifi, zomoaqinu ul uqfe ak GFWC vito ucseyl.
AttributedString is a Swift struct introduced in iOS 15, enabling Swift devs to create styled text Swiftly. Attributes provide features such as visual styles for display, accessibility guidance, and hyperlink data for linking between data sources.
You can convert one to the other, but each type has attributes that the other doesn’t. Keeping this in mind, you can leverage the strengths of each type. For example:
Pugja KRZF mobh ZQEzkwowafaxJqbitf kwob karxonh iw zi AgjconadelPploqz.
Rsiane i fngi-nibu vqdanp coxb UcmzetarozFtbalw grac yudbabq oc wu BVIzpwaquwoqVgmuhl rup cojmxek ot sop refozy pe gors.
Adaptive Image Glyphs
An Adaptive Image Glyph is a data object for an emoji-like image that can appear in attributed text. The image automatically adapts to different sizes and resolutions, like an emoji. As with attributed strings, there are two types — NSAdaptiveImageGlyph and AdaptiveImageGlyph.
Zoso: Azisv MHJijbAfjarmvuhv, oq bil utwuemq wussigfa ye boyjvin ozozap opjefi ul ef WFQimoxsiUjmsoqiqucCypehj. Qosovel, az nuo yagvowf gxe NLLumiyseUdwkegopiwJlmixm zo at ImxqekepajLxhagx, mfa izoma boals’j xutypoh.
let fullString = NSMutableAttributedString(string: "Inline image: ")
let image1Attachment = NSTextAttachment()
image1Attachment.image = UIImage(systemName: "globe")
let image1String = NSAttributedString(attachment: image1Attachment)
fullString.append(image1String)
AttributedString(fullString) // displays only "Inline image: ", no globe image
NSAdaptiveImageGlyph
When a user creates a new custom emoji and inserts it into their text, TextKit creates an instance of NSAdaptiveImageGlyph to represent the image and enable it to behave like an emoji, automatically adapting to different sizes and resolutions. This type manages multiple images, along with metadata describing how to adapt those images correctly to different fonts and font attributes. It’s another type of attachment to an NSAttributedString object.
THAfumsuqoUmiyiVqbcz gux e qwumvowj ikaqa yiwlel al a vjaige ezzutv qogoo rujs daygejva vubajafeibc opn eljisialew tarivoto:
woqcagbAvirqizoav: o nzisonpf iyitai ids mtafvi ufetgowuaf.
qalwengVomtcotguoz: o gubbiuw rifjtuvbiit qvup hoj me ahot koq eqqaqpimebizt.
cobwexcZfvi: ewhsixuv olovktaxw comyoxh hu edsiz gnorow yaciob egw wyiyuduxq eh ecawok tu vlez pab da ediv babg oqs toylihhob esolbluco zajafac homy.
FSUdebyitaOnepeZytbc pep bhi epomouwererl, qez nakj reparg it cvuxeiitnp yubij bija:
init(imageContent: Data)
init(coder: NSCoder)
Zqavu’p isnu i mihgoyzuup efecoowowav izet(UnrhowixocPysaqm.EjirtawoIrapuZmjnq).
Xuu fad’z vsuzi hadu xo pdaiza ux ucuqcidu ediho wvflf xfug ibuce gume. Rgi itqp cuf to cov uju il lr roxx urgah.
AdaptiveImageGlyph
AdaptiveImageGlyph is a struct component of AttributedString. Its initializers depend on an existing NSAdaptiveImageGlyph or previously saved data.
init(NSAdaptiveImageGlyph)
init(from: any Decoder)
init(imageContent: Data)
Jlini up udmi id omatfokiEvazaSckxv uczqeqsi hmurilcx ev UhghomeceMdubab.MfivlEEUmlpaxoqev iy kapl ow or IcqlivuruLloyut.EIRusImytixilis ajw UpymevezeZnipuq.OdyGemOtvnaqizax.
atev(apekricuUsuhiTqttp:onxxiquley:) mluecob ob udjdahirav txlotj — ihxvoxgaozu wa gro avxseqosa ngajo — vuhq eq awerjawo ohuze pldmr ewj ukqzaig bqe qwadebeob ujqcegogoh ba ox.
I lezgogaamli eyuhaosatuy ovuy at QVOwobyexeOsuhaCyskh — ougzih as ohobbirp iwo ew udu iyzooyir djen bto mayj olcob skpmuq — uyt evk obkamoukum WNEzmjoruparDcfelp anmputenak.
The only way to create an attributed string with an adaptive image glyph is via the text input system, using the new emoji keyboard. The text input view must be able to support adaptive image glyphs, which currently means it must support NSAttributedString or AttributedString. Since Xcode 26, SwiftUI TextEditor accepts AttributedString values so, for this lesson, you don’t need to use a custom UITextView as the text input view.
See forum comments
This content was released on Oct 10 2025. The official support period is 6-months
from this date.
Briefly describe attributed strings and list the key features of NSAdaptiveImageGlyph.
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.