Skip to content

Instantly share code, notes, and snippets.

@imjhk03
Last active April 30, 2024 09:18
Show Gist options
  • Select an option

  • Save imjhk03/f395fe06997693839c187ea033b660a3 to your computer and use it in GitHub Desktop.

Select an option

Save imjhk03/f395fe06997693839c187ea033b660a3 to your computer and use it in GitHub Desktop.
Swift Array Cheat Sheet
// 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
@imjhk03
Copy link
Author

imjhk03 commented Apr 30, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment