I want to assign the first char of a string. Of course there is a advance function, but to me (I come from C++) it is much easier to read when simply using [index]. So I defined an extension for String type:
extension String {
subscript (i: Int) -> Character {
return self[advance(self.startIndex, i)]
}
subscript (i: Int) -> String {
return String(self[i] as Character)
}
...
This works fine for a condition like:
if (s[0] == "u")
but when assigning this value like
var c = s[0]
I get an error that compiler can't subscript String with type of int. But where is the difference?