Skip to content

Commit 21155bd

Browse files
committed
Specify preference for structs over classes
Also note that if you _are_ going to use a `class`, you should default to marking it as `final`.
1 parent 8514a0a commit 21155bd

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

style/swift/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Swift
55

66
* Keep up with the Objective-C style guide above. Will highlight differences
77
here.
8+
* Prefer `struct`s over `class`es wherever possible
9+
* Default to marking classes as `final`
810
* Use `let` whenever possible to make immutable variables
911
* Name all parameters in functions and enum cases
1012
* Use trailing closures

style/swift/sample.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
import Foundation // or not
44

5+
// MARK: Types
6+
7+
// Prefer structs over classes
8+
struct User {
9+
let name: String
10+
}
11+
12+
// When using classes, default to marking them as final
13+
final class MyViewController: UIViewController {
14+
}
15+
516
// MARK: Closures
617

718
// Use typealias when closures are referenced in multiple places

0 commit comments

Comments
 (0)