我想从标签中读取字符串并删除它的最后一个字符。Swift字符串操作不起作用
这是我正在尝试:
@IBAction func del(sender: UIButton) {
let str = telephone.text!;
let newstr = str.remove(at: str.index(before: str.endIndex))
telephone.text = newstr;
}
当我跑,我得到一个错误:
"String" does not have a member named "remove"
有人可以帮我找出这个问题? 刚开始学习迅速:(
在游乐场我可以编译你的代码,并预期它会成功。尝试使用'let str =“Test”'进行测试。顺便说一句,你不需要在行尾使用';'。 – LinusGeffarth
我尝试了“东西”作为文本和IDE仍然给出了同样的错误:( – ssdesign
'删除(在:))突变接收器,并期望一个*变量* –