Skip to content

Instantly share code, notes, and snippets.

@toshi0383
Created October 31, 2016 07:55
Show Gist options
  • Save toshi0383/6e59abaf3e651811fc1cc1e5ba9e943b to your computer and use it in GitHub Desktop.
Save toshi0383/6e59abaf3e651811fc1cc1e5ba9e943b to your computer and use it in GitHub Desktop.
ついついintをsubscriptに突っ込みたくなるけど違うんでしたねー。 #CodePiece
let a = "89078"
for i in (0..<a.characters.count) {
// let index: Int = i // <= wrong!
let index: String.CharacterView.Index =
a.characters.index(a.startIndex, offsetBy: i)
print(a[index])
}
// 8
// 9
// 0
// 7
// 8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment