Skip to content

Commit 6a078bf

Browse files
authored
Improve concurrency example of transient invalid states (#344)
The old example actually makes an atomic update to the array of temperatures because it uses `map`. Updating them in a `for` loop makes it more obvious that some temperatures will be Fahrenheit and some Celsius when the program's in the middle of the loop. Fixes: rdar://139633262
2 parents 808839a + 66fa7be commit 6a078bf

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

TSPL.docc/LanguageGuide/Concurrency.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,8 +1107,8 @@ the code below converts measured temperatures from Fahrenheit to Celsius:
11071107
```swift
11081108
extension TemperatureLogger {
11091109
func convertFahrenheitToCelsius() {
1110-
measurements = measurements.map { measurement in
1111-
(measurement - 32) * 5 / 9
1110+
for i in measurements.indices {
1111+
measurements[i] = (measurements[i] - 32) * 5 / 9
11121112
}
11131113
}
11141114
}

0 commit comments

Comments
 (0)