Skip to content

Commit 5ccb0bb

Browse files
committed
Editorial changes.
1 parent 532ce7e commit 5ccb0bb

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

proposals/NNNN-init-accessors.md

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ struct Angle {
7070
self.degrees = degrees // initializes 'self.degrees' directly
7171
}
7272

73-
init(radians: Double) {
74-
self.radians = radians // calls init accessor with 'radians'
73+
init(radiansParam: Double) {
74+
self.radians = radiansParam // calls init accessor for 'self.radians', passing 'radiansParam' as the argument
7575
}
7676
}
7777
```
@@ -82,7 +82,7 @@ Access effects allow a computed property to be initialized by placing its conten
8282

8383
```swift
8484
struct ProposalViaDictionary {
85-
private var dictionary: [String: String] = [:]
85+
private var dictionary: [String: String]
8686

8787
var title: String {
8888
init(newValue) accesses(dictionary) {
@@ -103,6 +103,7 @@ struct ProposalViaDictionary {
103103
}
104104

105105
init(title: String, text: String) {
106+
self.dictionary = [:] // 'dictionary' must be initialized before init accessors access it
106107
self.title = title // calls init accessor to insert title into the dictionary
107108
self.text = text // calls init accessor to insert text into the dictionary
108109

@@ -158,17 +159,26 @@ init-effect -> 'initializes' '(' identifier-list ')'
158159
159160
access-effect -> 'accesses' '(' identifier-list ')'
160161
161-
identifier-list -> identifier
162-
identifier-list -> identifier ',' identifier-list
163-
164162
accessor-block -> init-accessor
165163
```
166164

167-
The `identifier` in an `init-accessor-parameter`, if provided, is the name of the parameter that contains the initial value. If not provided, a parameter with the name `newValue` is automatically created.
165+
The `identifier` in an `init-accessor-parameter`, if provided, is the name of the parameter that contains the initial value. If not provided, a parameter with the name `newValue` is automatically created. The minimal init accessor has no parameter list and no initialization effects:
166+
167+
```swift
168+
struct Minimal {
169+
var value: Int {
170+
init {
171+
print("init accessor called with \(newValue)")
172+
}
173+
174+
get { 0 }
175+
}
176+
}
177+
```
168178

169179
### `init` accessor signatures
170180

171-
`init` accessor declarations can optionally specify a signature. An `init` accessor signature is composed of a parameter for the initial value, a list of stored properties that are initialized by this accessor specified with the contextual `initializes` keyword, and a list of stored properties that are accessed by this accessor specified with the contextual `accesses` keyword, all of which are optional:
181+
`init` accessor declarations can optionally specify a signature. An `init` accessor signature is composed of a parameter list, followed by an initialization effects specifier clause. The initialization effects can include a list of stored properties that are initialized by this accessor specified in the argument list of the contextual `initializes` keyword, and a list of stored properties that are accessed by this accessor specified in the argument list of the contextual `accesses` keyword, each of which are optional:
172182

173183
```swift
174184
struct S {
@@ -190,9 +200,9 @@ struct S {
190200

191201
If the accessor uses the default parameter name `newValue` and neither initializes nor accesses any stored property, the signature is not required.
192202

193-
Init accessors can subsume the initialization of a set of stored properties. Subsumed stored properties are specified through the `initializes:` clause of the accessor signature. The body of an `init` accessor is required to initialize the subsumed stored properties on all control flow paths.
203+
Init accessors can subsume the initialization of a set of stored properties. Subsumed stored properties are specified through the `initializes` effect. The body of an `init` accessor is required to initialize the subsumed stored properties on all control flow paths.
194204

195-
Init accessors can also require a set of stored properties to already be initialized when the body is evaluated, which are specified through the `accesses:` cause of the signature. These stored properties can be accessed in the accessor body; no other properties or methods on `self` are available inside the accessor body, nor is `self` available as a whole object (i.e., to call methods on it).
205+
Init accessors can also require a set of stored properties to already be initialized when the body is evaluated, which are specified through the `accesses` effect. These stored properties can be accessed in the accessor body; no other properties or methods on `self` are available inside the accessor body, nor is `self` available as a whole object (i.e., to call methods on it).
196206

197207
### Definite initialization of properties on `self`
198208

@@ -289,7 +299,7 @@ init(x: Int, y: Int) {
289299
}
290300
```
291301

292-
A memberwise initializer cannot be synthesized if a stored property that is an `accesses` effect of a computed property is ordered after that computed property in the source code:
302+
A memberwise initializer will not be synthesized if a stored property that is an `accesses` effect of a computed property is ordered after that computed property in the source code:
293303

294304
```swift
295305
struct S {

0 commit comments

Comments
 (0)