Skip to content

Instantly share code, notes, and snippets.

@deathlezz
Created October 17, 2021 08:35
Show Gist options
  • Save deathlezz/3a0d39460ad9700802a5048251a3dc35 to your computer and use it in GitHub Desktop.
Save deathlezz/3a0d39460ad9700802a5048251a3dc35 to your computer and use it in GitHub Desktop.
Simple use of arrays in Swift 5.
//
// Simple use of arrays
//
// basic array
var band = ["Steve", "Bob", "Kevin"]
print(band[0]) // Steve
band.append("Jack")
print(band) // ["Steve", "Bob", "Kevin", "Jack"]
band.remove(at: 0)
print(band) // ["Bob", "Kevin", "Jack"]
band.insert("Harold", at: 3)
print(band) // ["Bob", "Kevin", "Jack", "Harold"]
// empty array
var empty: [Int] = [] // or var empty = [Int]()
empty.append(3)
empty.append(2)
empty.append(1)
print(empty[2]) // 1
print(empty) // [3, 2, 1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment