Created
October 17, 2021 08:35
-
-
Save deathlezz/3a0d39460ad9700802a5048251a3dc35 to your computer and use it in GitHub Desktop.
Simple use of arrays in Swift 5.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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