Skip to content

Commit b5bb2a8

Browse files
committed
Add note for mandatory self in closures
1 parent 40f4458 commit b5bb2a8

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

README.markdown

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ The example above demonstrates the following style guidelines:
193193

194194
Avoid using `self` since Swift does not require it to access an object's properties or invoke its methods.
195195

196-
The only reason for requiring the use of `self` is to differentiate between property names and arguments when initializing a class or structure:
196+
The only reasons for requiring the use of `self` is to differentiate between property names and arguments when initializing a class or structure and when referencing properties in closures to make capture semantics explicit:
197197

198198
```swift
199199
class BoardLocation {
@@ -202,6 +202,10 @@ class BoardLocation {
202202
init(row: Int,column: Int) {
203203
self.row = row
204204
self.column = column
205+
206+
let closure = { () -> () in
207+
println(self.row)
208+
}
205209
}
206210
}
207211
```

0 commit comments

Comments
 (0)