2
我试图从使用removeAtIndex
函数String
的字符串中删除Character
。但它撞上了操场。RemoveAtIndex崩溃游乐场
下面是完整的代码:
let string = "Some String"
let start = advance(string.startIndex, 2)
let x = string.removeAtIndex(start)
我试图从使用removeAtIndex
函数String
的字符串中删除Character
。但它撞上了操场。RemoveAtIndex崩溃游乐场
下面是完整的代码:
let string = "Some String"
let start = advance(string.startIndex, 2)
let x = string.removeAtIndex(start)
您已经声明string
与let
这使得它不变。既然你只能在可变String
叫removeAtIndex
,您可以通过var
声明string
,而不是解决这个问题:
var string = "Some String"
let start = advance(string.startIndex, 2)
let x = string.removeAtIndex(start)
注:在Xcode 6.1以上的作品,但崩溃编译器在Xcode 6.0 。
有关的Xcode 6.0,使用全局removeAtIndex
功能,而不是工作:
var string = "Some String"
let start = advance(string.startIndex, 2)
let x = removeAtIndex(&string, start)
Nope.I进行了更改,但它的崩溃。这是来自操场的错误。 “ ”尝试与助手应用程序通信时发生错误,您可能需要在游乐场再次运行之前重新启动Xcode。“ – Fido 2014-10-19 11:04:39
这是Xcode 6.0中的一个编译器错误。它将在Xcode 6.1中工作。我为Xcode 6.0添加了一个解决方法。 – 2014-10-19 15:54:22