Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typo in high-score board instructions #752

Merged
merged 4 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions concepts/dictionaries/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let constants: = ["pi": 3.14159, "e": 2.71828, "phi": 1.618033, "avogadro": 6.02
- Empty dictionaries can be written by following the type name of the dictionary by a pair of parenthesis, e.g. `[Int: String]()`, or, if the type can be determined from the context, as just a pair of square brackets surrounding a colon, `[:]`.
- Type names for dictionaries are written in one of two ways: `Dictionary<K, V>` or `[K: V]` where `K` is the type of the keys in the dictionary and `V` is the type of the values.
- Dictionary elements can be accessed using subscript notation, e.g. `addresses["The Simpsons"]`.
- Values returned from these look-ups are optionals; `nil` is returned if a requested key is not present in the dictionary.```
- Values returned from these look-ups are optionals; `nil` is returned if a requested key is not present in the dictionary.
- To avoid the optional type of the return, one can supply a default value to return if the key in not found in the dictionary.

```swift
Expand All @@ -35,7 +35,19 @@ let betty = addresses["Betty Cooper", default: "Address unknown"]
- This can be used to update the value associated with a key or to add a new _key: value_ pair to the dictionary.
- Dictionaries can be sorted by passing a sorting function into the dictionary's `sorted(by:)` method.
- For-in loops can be used to iterate through the _key: value_ pairs of a dictionary
- Each pair is presented as a tuple and can be destructured like other tuples to assign each element to a name. For example, to print out the address book, on can write:
- Each pair is presented as a tuple and can be destructured like other tuples to assign each element to a name. For example, to print out the address book, one can write:

```swift
for (name, address) in addresses {
print("\(name) lives at \(address)")
}

// prints out:
// Betty Cooper lives at 111 Queens Ave.
// The Munsters lives at 1313 Mockingbird Lane
// The Simpsons lives at 742 Evergreen Terrace
// Buffy Summers lives at 1630 Revello Drive
```

[The other methods][dictionary-docs] available for working with dictionaries can be seen in the Apple Swift API documentation.

Expand Down
2 changes: 1 addition & 1 deletion exercises/concept/high-score-board/.docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Dictionaries are one of Swift's three primary collection types. Dictionaries store mappings between _keys_ which are elements of one type and _values_ which are elements of another type (possibly the same type as that of the keys).

Dictionary literals are written as a series of `key: value` pairs, separated by commas, enclosed in square brackets. Empty dictionaries can be written by following the type name of the dictionary by a pair of parenthesis, e.g. `[Int: String]()`, or, if the type can be determined from the context, as just a pair of square brackets surrounding a colon, `[:]`. Type names for dictionaries are written in one of two ways: `Dictionary<K, V>` or `[K: V]` where `K` is the type of the keys in the dictionary and `V` is the type of the values. When creating an empty array, the type must be specified.
Dictionary literals are written as a series of `key: value` pairs, separated by commas, enclosed in square brackets. Empty dictionaries can be written by following the type name of the dictionary by a pair of parenthesis, e.g. `[Int: String]()`, or, if the type can be determined from the context, as just a pair of square brackets surrounding a colon, `[:]`. Type names for dictionaries are written in one of two ways: `Dictionary<K, V>` or `[K: V]` where `K` is the type of the keys in the dictionary and `V` is the type of the values. When creating an empty dictionary, the type must be specified.

```swift
var addresses: Dictionary<String, String> = ["The Munsters": "1313 Mockingbird Lane", "The Simpsons": "742 Evergreen Terrace", "Buffy Summers": "1630 Revello Drive"]
Expand Down