I have an array made from a struct that holds multiple arrays and when trying to replace a value within the subarray I am met with an error:
Fatal error: Index out of range
struct Main {
var city: String
var pop: Int
var color: String
}
class Home {
var mainArray = [[Main]]()
func update() {
let data = Main(city: "SF", pop: 2, color: "orange")
mainArray.append(data)
for var subArray in mainArray {
for var i in subArray {
var newCity = "SB"
i.city = newCity
subArray[0].city = i.city
}
}
}
}
var mainArrayis not valid Swift code. Please update your question with the actual code you're using.mainArray.append(data)still doesn't compile.