阵列删除对象在:?字符串可能无法用 'Int' 索引,它有可变大小元素错误

Array remove object at: ? String may not be indexed with 'Int', it has variable size elements error

你好,我想从 swift 中的数组中删除对象 3 给我错误

String may not be indexed with 'Int', it has variable size elements error

我的代码在这里

var itemListcomming = String()
itemListcomming = itemListcomming.remove(at: 16)

有什么想法吗?

谢谢

String in Swift 2 在索引方面有点麻烦,Swift 3 更是如此。你不能给出 Int 作为索引,但操纵 startIndex / endIndex 到达你想要的位置。自 Swift 1.0.

以来一直如此

无论如何,如果你想删除字符串的第16个字符:

var itemListcomming = "Lorem ipsum dolor sit amet"
let index = itemListcomming.index(itemListcomming.startIndex, offsetBy: 16)
itemListcomming.remove(at: index)

print(itemListcomming)