Strings and characters
At an intuitive level, we understand text to consist of words that themselves consist of letters, all chained together in some meaningful fashion (Dr. Seuss books and the poetry of E.E. Cummings excepted). However, the further we look into the technicalities of providing the user with numerous alphabets, symbols, and emojis, the more we realize that this simple intuitive perception of text hides a large number of issues that we, as developers, must grapple with.
Drawing text using default fonts and styles is very easy. But the more we understand about strings and text, the better we are equipped to make use of the rich set of tools at our disposal. And toolsets don't come much richer than macOS.
What is a String in Swift?
A Swift String
is a struct
that adopts the Equatable
and Comparable
protocols (as well as several others). As all structs, it is passed by value. It has a CharacterView
property (with which we will seldom interact explicitly), which is a collection ...