Last active
May 8, 2019 02:31
-
-
Save RinniSwift/f6d067d66105b9cf5215049d871af288 to your computer and use it in GitHub Desktop.
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
// 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