Reputation:
My code is not working. All I am trying to do is get the number inserted into the struct's internal array. Right now this is not working:
@IBAction func move(_ sender: Any) {
bad.numbers.insert(0, at: 0)
}
struct bad {
var numbers: [Int] = [1, 2, 3]
}
Upvotes: 1
Views: 90
Reputation: 236420
You need to declare your numbers property as static. Btw it is Swift convention to name your structures starting with an uppercase letter:
struct Bad {
static var numbers: [Int] = [1, 2, 3]
}
And to insert elements at index 0, you need to call it like this :
Bad.numbers.insert(0, at: 0)
print(Bad.numbers) // "[0, 1, 2, 3]\n"
Upvotes: 3