在Swift4中,String是Collections. 您将不再在字符串上使用characters属性.
func swapCharacters(input:String,index1:Int,index2:Int)-> String { // logic to swap }
let input = "ABCDEFGH"
Run Code Online (Sandbox Code Playgroud)
如果我用(输入,3,8)调用该函数,那么输出应该是
输出: ABC H EFG D.
注意:在Swift4中,字符串是集合.