2014-10-19 52 views
2

我試圖從使用removeAtIndex函數String的字符串中刪除Character。但它撞上了操場。RemoveAtIndex崩潰遊樂場

下面是完整的代碼:

let string = "Some String" 
let start = advance(string.startIndex, 2) 
let x = string.removeAtIndex(start) 

回答

2

您已經聲明stringlet這使得它不變。既然你只能在可變StringremoveAtIndex,您可以通過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) 
+0

Nope.I進行了更改,但它的崩潰。這是來自操場的錯誤。 「 」嘗試與助手應用程序通信時發生錯誤,您可能需要在遊樂場再次運行之前重新啓動Xcode。「 – Fido 2014-10-19 11:04:39

+0

這是Xcode 6.0中的一個編譯器錯誤。它將在Xcode 6.1中工作。我爲Xcode 6.0添加了一個解決方法。 – 2014-10-19 15:54:22