Swift 练笔 —— 逆转字符串

/***********************************************************
@Execise: 
    A function used to reverse string
    字符串逆转函数
@notice:
    1. type 'String' does not comform to protocol 'Sequence'
        字符串类型不符合元组协议
    2. 'reverse()' has been renamed to 'reversed()'
        reverse() 方法已经被重命名为 reversed()
***********************************************************/

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

// example
let original = "123abc❤我"
print("original string : \(original)")                  //original string : 123abc❤我
print("reversed string : " + reverseString(original))   //reversed string : 我❤cba321

你可能感兴趣的:(Swift 练笔 —— 逆转字符串)