Skip to content

Instantly share code, notes, and snippets.

@RinniSwift
Last active May 8, 2019 02:31
Show Gist options
  • Save RinniSwift/f6d067d66105b9cf5215049d871af288 to your computer and use it in GitHub Desktop.
Save RinniSwift/f6d067d66105b9cf5215049d871af288 to your computer and use it in GitHub Desktop.
// 1. empty array initialization
let numbers = [Int]()
let nums: [Int] = []
let newNumbers = Array<Int>()
let newNums: Array<Int> = Array()
// 2. preinitializing a fixed number of default values
let repeatSwift = Array<String>(repeating: "Swift", count: 5) // ["Swift", "Swift", "Swift", "Swift", "Swift"]
// or
let repeatSwift = Array(repeating: "Swift", count: 5) // ["Swift", "Swift", "Swift", "Swift", "Swift"]
// 3. array literals
let flowers = ["Lily", "Rose", "Daisy", "Scarlet", "Tulip"] // ["Lily", "Rose", "Daisy", "Scarlet", "Tulip"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment