Swift3 Type 'String' does not conform to protocol 'Sequence'

前端之家收集整理的这篇文章主要介绍了Swift3 Type 'String' does not conform to protocol 'Sequence'前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

在Swift3中如果要用for循环遍历字符串String,用以前的方法可能会报标题中的错误,只需要这么做就好了

for character in string.characters {}

字符串倒序也很容易

func reverseString(string: String) -> String {
  return String(string.characters.reverse())
}

In Swift 3reverse()has been renamed toreversed() 原文链接:https://www.f2er.com/swift/322629.html

猜你在找的Swift相关文章