Skip to content

Commit 6fe4a46

Browse files
committed
Editorial changes.
1 parent 532ce7e commit 6fe4a46

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

proposals/NNNN-init-accessors.md

Lines changed: 18 additions & 8 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 {

0 commit comments

Comments
 (0)