Extensions
The following extensions are available globally.
-
An arbitrary Unicode string value.Unicode-Correct ===============Swift strings are designed to be Unicode-correct. In particular, the APIs make it easy to write code that works correctly, and does not surprise end-users, regardless of where you venture in the Unicode character space. For example,
- The
==operator checks for Unicode canonical equivalence, so two different representations of the same string will always compare equal. - String elements are
Characters(Unicode extended grapheme clusters), a unit of text that is meaningful to most humans.
Dictionary<String, T>in a running program depends on a given string comparison having a single, stable result. Therefore, Swift always uses the default, un-tailored Unicode algorithms for basic string operations.ImportingFoundationendows swift strings with the full power of theNSStringAPI, which allows you to choose more complex locale-sensitive operations explicitly.Value Semantics ===============Each string variable,letbinding, or stored property has an independent value, so mutations to the string are not observable through its copies::var a =
Strings use Copy-on-Write so that their data is only copied lazily, upon mutation, when more than one string instance is using the same buffer. Therefore, the first in any sequence of mutating operations may costfoo
var b = a b[b.endIndex.predecessor()] =x
println(a=\(a), b=\(b)
) // a=foo, b=foxO(N)time and space, whereNis the length of the string’s (unspecified) underlying representation,.Growth and Capacity ===================When a string’s contiguous storage fills up, new storage must be allocated and characters must be moved to the new storage.Stringuses an exponential growth strategy that makesappenda constant time operation when amortized over many invocations.Objective-C Bridge ==================Stringis bridged to Objective-C asNSString, and aStringthat originated in Objective-C may store its characters in anNSString. Since any arbitrary subclass ofNSSStringcan become aString, there are no guarantees about representation or efficiency in this case. SinceNSStringis immutable, it is just as though the storage was shared by some copy: the first in any sequence of mutating operations causes elements to be copied into unique, contiguous storage which may costO(N)time and space, whereNis the length of the string representation (or more, if the underlyingNSStringis has unusual performance characteristics). See moreDeclaration
Swift
struct String - The
-
A 64-bit signed integer value type.
See moreDeclaration
Swift
struct Int : SignedIntegerType -
Undocumented
See more -
Undocumented
See more -
A value type whose instances are either
See moretrueorfalse.Declaration
Swift
struct Bool -
Undocumented
See more
-
Undocumented
See more
-
Undocumented
See more
-
Undocumented
See more
-
Undocumented
See more
View on GitHub
Extensions Reference