Last active
April 30, 2024 09:18
-
-
Save imjhk03/f395fe06997693839c187ea033b660a3 to your computer and use it in GitHub Desktop.
Swift Array Cheat Sheet
This file contains hidden or 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
| // Initialize an array with fixed number of default values | |
| var digitCounts = Array(repeating: 0, count: 5) | |
| // [0, 0, 0, 0, 0] | |
| // Convert an array of integers to an array of strings, use 'map()' | |
| let numbers: [Int] = [1, 2, 3, 4, 5] | |
| let stringArray = numbers.map { String($0) } | |
| // Find the maximum element in an array, can be nil | |
| let numbers = [1, 2, 3, 4, 5] | |
| let max = numbers.max() // max will be 5 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Array | Apple Developer Documentation