What is the proper way to append an element on the end of an optional array? Let\'s say I have an optional array, myArray, and I want to append \'99\' on the end. Append() d
Instead of using append, try using array merge operator. Because the result is an optional use nil coalescing operator to assign one element array when initial array was nil.
var myArray = [Int]?()
myArray? += [99]
myArray = myArray ?? [99]
I tried to merge it into one line expression but unfortunately Swift doesn't like it
myArray = (myArray? += [99]) ?? [99]