Skip to content

Commit f990214

Browse files
amartini51Chuck Toporek
andcommitted
Incorporate edits.
Fixes: rdar://111129109 Co-authored-by: Chuck Toporek <chuck_toporek@apple.com>
1 parent 14c9142 commit f990214

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

Style.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ For example:
171171
If the operator doesn’t have an established English name,
172172
make sure you get tech review on the name you invent for it.
173173

174+
## optional binding
175+
176+
Omit the article: "use optional binding", not "use an optional binding".
177+
174178
## passive voice
175179

176180
In general,

TSPL.docc/LanguageGuide/TheBasics.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ after the name of the type that the optional contains ---
12291229
for example, the type of an optional `Int` is `Int?`.
12301230
An optional `Int` always contains
12311231
either some `Int` value or no value at all.
1232-
It can't contain anything else, like a `Bool` value or a `String` value.
1232+
It can't contain anything else, like a `Bool` or `String` value.
12331233

12341234
### nil
12351235

@@ -1256,7 +1256,7 @@ serverResponseCode = nil
12561256
-->
12571257

12581258
If you define an optional variable without providing a default value,
1259-
the variable is automatically set to `nil` for you:
1259+
the variable is automatically set to `nil`:
12601260

12611261
```swift
12621262
var surveyAnswer: String?
@@ -1277,7 +1277,7 @@ by comparing the optional against `nil`.
12771277
You perform this comparison with the “equal to” operator (`==`)
12781278
or the “not equal to” operator (`!=`).
12791279

1280-
If an optional has a value, it's considered to be “not equal to” `nil`:
1280+
If an optional has a value, it's considered as “not equal to” `nil`:
12811281

12821282
```swift
12831283
let possibleNumber = "123"
@@ -1304,14 +1304,14 @@ You can't use `nil` with non-optional constants or variables.
13041304
If a constant or variable in your code needs to work with
13051305
the absence of a value under certain conditions,
13061306
declare it as an optional value of the appropriate type.
1307-
A constant or variable that's declared as a non-optional value,
1307+
A constant or variable that's declared as a non-optional value
13081308
is guaranteed to never contain a `nil` value.
13091309
If you try to assign `nil` to a non-optional value,
13101310
you'll get a compile-time error.
13111311

13121312
This separation of optional and non-optional values
13131313
lets you explicitly mark what information can be missing,
1314-
and makes it easier to write correct code that handle missing values.
1314+
and makes it easier to write code that handle missing values.
13151315
You can't accidentally treat an optional as if it were non-optional
13161316
because this mistake produces an error at compile time.
13171317
After you unwrap the value,
@@ -1322,7 +1322,7 @@ in different parts of your code.
13221322
When you access an optional value,
13231323
your code always handles both the `nil` and non-`nil` case.
13241324
There are several things you can do when a value is missing,
1325-
which are described in more detail in the following sections:
1325+
as described in the following sections:
13261326

13271327
- Skip the code that operates on the value when it's `nil`.
13281328

@@ -1392,9 +1392,9 @@ set a new constant called `actualNumber` to the value contained in the optional.
13921392
If the conversion is successful,
13931393
the `actualNumber` constant becomes available for use within
13941394
the first branch of the `if` statement.
1395-
It has already been initialized with the value contained *within* the optional,
1395+
It has already been initialized with the value contained within the optional,
13961396
and has the corresponding non-optional type.
1397-
In this case, the type of `possibleNumber` is `Int?`
1397+
In this case, the type of `possibleNumber` is `Int?`,
13981398
so the type of `actualNumber` is `Int`.
13991399

14001400
If you don't need to refer to the original, optional constant or variable
@@ -1431,8 +1431,8 @@ If `myNumber` has a value,
14311431
the value of a new constant named `myNumber` is set to that value.
14321432
Inside the body of the `if` statement,
14331433
writing `myNumber` refers to that new non-optional constant.
1434-
Before the beginning of the `if` statement and after its end,
1435-
writing `myNumber` refers to the original optional integer constant.
1434+
Writing `myNumber` before or after the `if` statement
1435+
refers to the original optional integer constant.
14361436

14371437
Because this kind of code is so common,
14381438
you can use a shorter spelling to unwrap an optional value:
@@ -1532,9 +1532,9 @@ as described in <doc:ControlFlow#Early-Exit>.
15321532

15331533
Another way to handle a missing value is to supply
15341534
a default value using the nil-coalescing operator (`??`).
1535-
If the optional on the left side of the `??` isn't `nil`,
1535+
If the optional on the left of the `??` isn't `nil`,
15361536
that value is unwrapped and used.
1537-
Otherwise, the value on the right side of `??` is used.
1537+
Otherwise, the value on the right of `??` is used.
15381538
For example,
15391539
the code below greets someone by name if one is specified,
15401540
and uses a generic greeting when the name is `nil`.
@@ -1591,11 +1591,11 @@ Both versions of the code above depend on `convertedNumber`
15911591
always containing a value.
15921592
Writing that requirement as part of the code,
15931593
using either of the approaches above,
1594-
lets your code check that the requirement is true at run time.
1594+
lets your code check that the requirement is true at runtime.
15951595

15961596
For more information about enforcing data requirements
15971597
and checking assumptions at runtime,
1598-
see <doc:TheBasics#Assertions-and-Preconditions> below.
1598+
see <doc:TheBasics#Assertions-and-Preconditions>.
15991599

16001600
### Implicitly Unwrapped Optionals
16011601

@@ -1897,11 +1897,11 @@ for recoverable or expected errors.
18971897
Because a failed assertion or precondition
18981898
indicates an invalid program state,
18991899
there's no way to catch a failed assertion.
1900-
Trying to recover from an invalid state isn't possible ---
1901-
because the assertion failed,
1902-
you know that at least one piece of the program's data is invalid,
1900+
Recovering from an invalid state is impossible.
1901+
When an assertion fails,
1902+
at least one piece of the program's data is invalid ---
19031903
but you don't know why it's invalid
1904-
or what additional state is also invalid.
1904+
or whether an additional state is also invalid.
19051905

19061906
Using assertions and preconditions
19071907
isn't a substitute for designing your code in such a way

0 commit comments

Comments
 (0)