Swift3-Type 'String' does not conform to protocol 'Sequence'
遍历字符串时出错如下:
Type ‘String’ does not conform to protocol ‘Sequence’
这是由于在swift3中修改了,改为如下写法:
/*
* 1、字符串
*/
print("1、字符串")
//Swift语言中,字符串中可以加入任何语言文字的字符
//遍历字符串
var str:String = "Hello,Swift,你好!"
for ch in str.characters{
print("\(ch)")
}
//倒叙字符串
func reverseString(string: String) -> String {
return String(string.characters.reversed())
}
var reverseStr = reverseString(string:str)
print("倒叙字符串\n\(reverseStr)")
还没有评论,来说两句吧...