Skip to content

Instantly share code, notes, and snippets.

@iJKTen
Created June 10, 2020 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iJKTen/4dac13b6cf6af7d0d588d1ed7ee36f31 to your computer and use it in GitHub Desktop.
Save iJKTen/4dac13b6cf6af7d0d588d1ed7ee36f31 to your computer and use it in GitHub Desktop.
var arr = [1, 2, 3, 4]
// Another way to create an empty array of integers
var arr: [Int] = []
// Long way to create an empty array of integers
var arr: Array<Int> = Array()
// Create a new array with a size and a default value of 0 for all the elements
var arr = Array(repeating: 0, count: 8)
arr.append(1)
arr.append(2)
// Append an array
arr.append(contentsOf: [3, 4, 5, 6, 7, 8])
arr[0]
arr[1]
arr[2]
arr[3]
arr[4]
arr[5]
arr[6]
arr[7]
for item in arr {
print(item)
}
for (index, item) in arr.enumerated() {
print(index, item)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment