Iterate through alphabet in Swift

前端 未结 8 1930
暗喜
暗喜 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 02:59

    "Pure functional" Swift 5 way:

    (Unicode.Scalar("A").value...Unicode.Scalar("Z").value).forEach({
        let letter = Unicode.Scalar($0)!
        print(letter)
        /* do other stuff with letter here */
    })
    

提交回复
热议问题