Iterate through alphabet in Swift

前端 未结 8 1889
暗喜
暗喜 2020-12-30 02:23

in Obj-C it was possible to iterate through alphabet with:

for (char x=\'A\'; x<=\'Z\'; x++) {

In Swift this isn\'t possible. Any idea h

8条回答
  •  囚心锁ツ
    2020-12-30 03:04

    In Swift, you can iterate chars on a string like this:

    Swift 2

    for char in "abcdefghijklmnopqrstuvwxyz".characters {
        println(char)
    }
    

    Swift 1.2

    for char in "abcdefghijklmnopqrstuvwxyz" {
        println(char)
    }
    

    There might be a better way though.

提交回复
热议问题