Skip to content

Instantly share code, notes, and snippets.

@RinniSwift
Created June 1, 2019 01:46
Show Gist options
  • Save RinniSwift/2ab0018b8bf06e6f3fcf0fc62c948ecb to your computer and use it in GitHub Desktop.
Save RinniSwift/2ab0018b8bf06e6f3fcf0fc62c948ecb to your computer and use it in GitHub Desktop.
var dict = ["blue": 2, "grey": 1, "red": 2]
// for-each loop
dict.forEach { pair in
print(pair)
}
// for-in loop
for pair in dict {
print(pair)
}
for (key, val) in dict {
print("key: \(key), value: \(val)")
}
for keys in dict.keys {
print(keys)
}
for values in dict.values {
print(values)
}
for (ind, pair) in dict.enumerated() {
print("index: \(ind), with pair: \(pair)")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment