Creates a string corresponding to the given collection of Unicode scalars.
SDK
- Xcode 6.0.1+
Framework
- Swift Standard Library
Declaration
init(_ unicodeScalars: String.UnicodeScalarView )
Parameters
unicodeScalars
A collection of Unicode scalar values.
Discussion
You can use this initializer to create a new string from a slice of another string’s unicode
view.
let picnicGuest = "Deserving porcupine"
if let i = picnicGuest.unicodeScalars.firstIndex(of: " ") {
let adjective = String(picnicGuest.unicodeScalars[..<i])
print(adjective)
}
// Prints "Deserving"
The adjective
constant is created by calling this initializer with a slice of the picnic
view.