I am trying to write some code which will append my array to this: ["e", "0", " ", "0"] but instead i am getting this : ["e", "0", "0"]. I don't understand why it is displaying the latter, since as far as I understand, index becomes 3 when i add 2 to it. Additionally I am also getting "fatal error: Array index out of range" when i try running this : TheTape.insert("0", atIndex: index+2). Here I also don't understand why it is out of range when i didnt specify the size of the array.
Thanks for your help!
import UIKit
var TheTape = [Any]()
var index = 0
if(TheTape.isEmpty){
TheTape.insert("e", atIndex: 0)
print(TheTape)
index++
TheTape.insert("0", atIndex: index)
print(TheTape)
index + 2
TheTape.insert("0", atIndex: index)
print(TheTape)
}
index + 2doesn't exist, so you're out of range.index++will be deprecated in Swift 2.2 and illegal in Swift 3.0. So the time to give up using it is now.