swift4 遍历String('characters' is deprecated: Please use String or Substring directly)

一、 之前学习swift时,使用characters进行遍历

let str = "Hello world!"
for s in str.characters {
      print(s)
 }

在swift3之后该方法被放弃,直接对String类型进行遍历

let str = "Hello world!"
for s in str {
      print(s)
 }

二、 获得String的字符数量

let str = "Hello world!"
let count = str.characters.count
print(count)

改为

let str = "Hello world!"
let count = str.count
print(count)

你可能感兴趣的:(swift4 遍历String('characters' is deprecated: Please use String or Substring directly))