1
其中存在語法錯誤。新斯威夫特:(將元素添加到數組中的Swift語法錯誤
var inputString: String = "Hello its question? </question> Oky its the answer"
let splitter: String = "</question>"
var splittedArray = [inputString .componentsSeparatedByString(splitter)]
var questionIndex = 0
var answerIndex = 0
var mQuestions = []
var mAnswers = []
for var index = 0; index < splittedArray.count; ++index {
if index % 2 == 0{
// Question comes first
splittedArray.append(mQuestions[questionIndex])
questionIndex++
}else{
// Answer comes second
splittedArray.append(mAnswers[answerIndex])
answerIndex++
}
}
錯誤是:
對象並不可轉換爲字符串,
在這行代碼
splittedArray.append(mQuestions[questionIndex])
一個對象或AnyObject? – 2014-12-05 06:39:33