Skip to content

Instantly share code, notes, and snippets.

@RinniSwift
Last active May 31, 2019 19:16
Show Gist options
  • Save RinniSwift/a37591f8c5a3ad2582ee966c82a8b2bc to your computer and use it in GitHub Desktop.
Save RinniSwift/a37591f8c5a3ad2582ee966c82a8b2bc to your computer and use it in GitHub Desktop.
// 1. empty dictionary initialization
var numbers = Dictionary<String, Int>()
var newNumbers: Dictionary<String, Int> = Dictionary()
// 2. empty dictionary initialization using dictionary literals
var nums = [String: Int]()
var newNums: [String: Int] = [:]
// 3. predefininig elements with dictionary literals
var romanNumerals = ["I": 1, "V": 5, "X": 10, "L": 50] // using type inference
var romanNums: [String: Int] = ["I": 1, "V": 5, "X": 10, "L": 50] // explicit type declaration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment