
It returns human readable characters count irrespective of scalar values. We can get the number of characters in a string by using count property on string type. It can be constructed by a single unicode scalar, so when we compare these two values, swift gives correct value as it knows the result irrespective of the constructing procedure(i.e by using a single unicode scalar or sequence of scalars) For example, a and a` are constructed by using grapheme clusters, and in the last character it is constructed by combining sequence of clusters. Swift uses Extended Grapheme Clusters, a sequence of one or more Unicode scalars, which produce a single human readable character. Behind the hood, Swift uses Unicode scalars, which is 21-bit number for each character. Swift’s String and Character types are fully Unicode-complaint, so it enables to read and write from/to any external source. Unicode : Unicode is an international standard for encoding, processing and representing text in different writing systems. Behind the scenes, Swift optimisation technique takes care of the copy functionality, whenever it needs, to increase the performance.Ī String literal is a sequence(collection) of characters surrounded by double quotation marks(“,”). So modifications take place when you perform. Swift String is value type, so when you pass, assign the string to another variable or constant, a new string will be created. Note : Swift String type is bridged with NSString class, so we can use all the NSString methods and APIs on the String type. Swift strings are composed of encoding-independent unicode characters and so we can avail the use of any character in a string with various Unicode representations. →String Interpolation : Inserting constants, literals, variables and expressions in the string type is called as String Interpolation. String mutability is managed by choosing constant(let) or variable(var) while declaring the type.

The contents of the string types are accessed in many ways including collection of characters, getting substrings by range, count, etc.

Swift strings are actually String (Struct) type. A string is a collection of characters such as “ hello world” or “ my medium account”.
