Iterate through a String Swift 2.0

后端 未结 4 1412
滥情空心
滥情空心 2020-11-30 08:21

I am trying to do a very simple piece of code in Swift playgrounds.

var word = \"Zebra\"

for i in word {
  print(i)
}

However, I always ge

4条回答
  •  半阙折子戏
    2020-11-30 09:04

    String doesn't conform to SequenceType anymore. However you can access the characters property of it this way:

    var word = "Zebra"
    
    for i in word.characters {
        print(i)
    }
    

    Note that the documentation hasn't been updated yet.

提交回复
热议问题