Skip to content

Commit 41b175b

Browse files
committed
Update access control kodecocodes#235
1 parent 953ab46 commit 41b175b

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

README.markdown

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -725,19 +725,27 @@ resource.request().onComplete { [weak self] response in
725725

726726
## Access Control
727727

728-
Full access control annotation in tutorials can distract from the main topic and is not required. Using `private` appropriately, however, adds clarity and promotes encapsulation. Use `private` as the leading property specifier. The only things that should come before access control are the `static` specifier or attributes such as `@IBAction` and `@IBOutlet`.
728+
Full access control annotation in tutorials can distract from the main topic and is not required. Using `private` and `fileprivate` appropriately, however, adds clarity and promotes encapsulation. Prefer `private` to `fileprivate` when possible. Using extensions may require you to use `fileprivate`.
729+
730+
Only explicitly use `open`, `public`, and `internal` when you require a full access control specification.
731+
732+
Use access control as the leading property specifier. The only things that should come before access control are the `static` specifier or attributes such as `@IBAction`, `@IBOutlet` and `@discardableResult`.
729733

730734
**Preferred:**
731735
```swift
736+
private let message = "Great Scott!"
737+
732738
class TimeMachine {
733-
private dynamic lazy var fluxCapacitor = FluxCapacitor()
739+
fileprivate dynamic lazy var fluxCapacitor = FluxCapacitor()
734740
}
735741
```
736742

737743
**Not Preferred:**
738744
```swift
745+
fileprivate let message = "Great Scott!"
746+
739747
class TimeMachine {
740-
lazy dynamic private var fluxCapacitor = FluxCapacitor()
748+
lazy dynamic fileprivate var fluxCapacitor = FluxCapacitor()
741749
}
742750
```
743751

@@ -780,6 +788,7 @@ while i < attendeeList.count {
780788
i += 1
781789
}
782790
```
791+
783792
## Golden Path
784793

785794
When coding with conditionals, the left hand margin of the code should be the "golden" or "happy" path. That is, don't nest `if` statements. Multiple return statements are OK. The `guard` statement is built for this.

0 commit comments

Comments
 (0)