How can I get the nth character of a string? I tried bracket([]) accessor with no luck.
[]
var string = \"Hello, world!\" var firstChar = string[
My very simple solution:
Swift 4.1:
let myString = "Test string" let index = 0 let firstCharacter = myString[String.Index(encodedOffset: index)]
Swift 5.1:
let firstCharacter = myString[String.Index.init(utf16Offset: index, in: myString)]