简体   繁体   中英

Append array of arrays Swift

I have an array of arrays called Lines

Numbers = [[1,2,3],[4,5,6],[7,8,9]]

and var numberInt = 10

how do i append this numberInt inside the last array of the multidimensional array? so it would look like

Numbers = [[1,2,3],[4,5,6],[7,8,9,10]]

Thank you.

Use Numbers[Numbers.count - 1] to get last one-dimensional array and append method to add item:

Numbers[Numbers.count - 1].append(numberInt)
print(Numbers) // prints "[[1, 2, 3], [4, 5, 6], [7, 8, 9, 10]]"

I'd also recommend you to take a look at this answer: https://stackoverflow.com/a/25128237/1796907

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM