Я получаю сообщение об ошибке "левая часть оператора мутации не является изменяемой"..‹" возвращает неизменяемое значение"
Я прочитал другой пост об изменении значений, но не могу понять, как применяются эти решения.
Код (и комментарии):
//populate array of 3 random numbers using correct answer and 2 incorrect choices
func insertIntoArray3(_ randomNumber: Int) -> Int {
for intJ in 0 ..< 2 += 1{
if arrayIndex != 3 {
checkIfExists(randomNumber)
if ifExists {
let randomNumber = 1 + random() % 10
insertIntoArray3(randomNumber)
} else {
array3[arrayIndex] = (randomNumber)
arrayIndex = arrayIndex + 1
}
}
}
return randomNumber
}
Пересмотренный код:
//populate array of 3 random numbers using correct answer and 2 incorrect choices
func insertIntoArray3(_ randomNumber: Int) -> Int {
for _ in 0 ..< 2 + 1{
if arrayIndex != 3 {
checkIfExists(randomNumber)
if ifExists {
let randomNumber = 1 + arc4random() % 10
insertIntoArray3(Int(randomNumber))
} else {
array3[arrayIndex] = (randomNumber)
arrayIndex = arrayIndex + 1
}
}
}
return randomNumber
}
Благодарю вас!
У меня тоже такая же ошибка....
//this function populates an array of the 40 image names
func populateAllImagesArray() {
for intIA in 1 ..< 11 += 1 {
tempImageName = ("\(intIA)")
imageArray.append(tempImageName)
tempImageName = ("\(intIA)a")
imageArray.append(tempImageName)
tempImageName = ("\(intIA)b")
imageArray.append(tempImageName)
tempImageName = ("\(intIA)c")
imageArray.append(tempImageName)
}
//println("imageArray: \(imageArray) ")
//println(imageArray.count)
}
Пересмотрено:
//this function populates an array of the 40 image names
func populateAllImagesArray() {
for intIA in 1 ..< 11 + 1 {
tempImageName = ("\(intIA)")
imageArray.append(tempImageName)
tempImageName = ("\(intIA)a")
imageArray.append(tempImageName)
tempImageName = ("\(intIA)b")
imageArray.append(tempImageName)
tempImageName = ("\(intIA)c")
imageArray.append(tempImageName)
}
//println("imageArray: \(imageArray) ")
//println(imageArray.count)
}
Благодарю вас!
for intIA in 1 ..< 11 += 1
здесь+=1
неверно. - person Ankit Thakur   schedule 02.11.2016