Last active
June 1, 2019 00:55
-
-
Save RinniSwift/0af1d7148ba80d625236f6cc6997902c 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
var dict = ["blue": 2, "grey": 1, "purple": 4, "red": 2] | |
// subscript(key:) | |
dict["blue"] // Optional(2) | |
// subscript(key:default:) | |
dict["grey", default: 0] // 1 | |
// subscript(position:) | |
if let ind = dict.firstIndex(where: { ($0.key == "red") }) { | |
print(dict[ind]) // (key: "red", value: 2) | |
} | |
if let indTwo = dict.index(forKey: "rin") { | |
print(dict[indTwo]) | |
} | |
// first | |
dict.first // Optional((key: "purple", value: 4)) | |
// randomElement() | |
dict.randomElement() // Optional((key: "grey", value: 1)) | |
// keys and values | |
dict.keys // ["purple", "red", "grey", "blue"] | |
dict.values // [1, 4, 2, 2] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment