Skip to content

Instantly share code, notes, and snippets.

@toshi0383
Created October 31, 2016 07:56
Show Gist options
  • Save toshi0383/cbd5e842f870eb69fdb45ac7b8c7879a to your computer and use it in GitHub Desktop.
Save toshi0383/cbd5e842f870eb69fdb45ac7b8c7879a to your computer and use it in GitHub Desktop.
ついついStringのsubscriptにIntを突っ込みたくなるけど違うんでしたねー。 #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