You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Remove Container-owned Constants Rules Modifies a few rules to match our switch away from keeping class-level constants in an intermediate container. The rule changes are fairly simple; additionally changes the format of 2.5's code example (things were about to get a bit weird with both comments and marks), and completely removes rule 3.1.16 (this rule was specifically a justification for keeping constants in an `enum` over `class` or `struct`, but without using containers the rule doesn't have much use) * Update README.md Update recommended case back to `camelCase` for constants * Better formatting + update "updated" line * Header changes * Fix remaining singletons reference
Copy file name to clipboardExpand all lines: README.md
+14-17Lines changed: 14 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ Make sure to read [Apple's API Design Guidelines](https://swift.org/documentatio
4
4
5
5
Specifics from these guidelines + additional remarks are mentioned below.
6
6
7
-
This guide was last updated for Swift 4.0 on January 23, 2018.
7
+
This guide was last updated for Swift 4.0 on February 14, 2018.
8
8
9
9
## Table Of Contents
10
10
@@ -172,7 +172,7 @@ if x == firstReallyReallyLongPredicateFunction()
172
172
173
173
***2.2** Use `PascalCase` for type names (e.g. `struct`, `enum`, `class`, `typedef`, `associatedtype`, etc.).
174
174
175
-
***2.3** Use `camelCase` (initial lowercase letter) for function, method, property, constant, variable, argument names, enum cases, etc.).
175
+
***2.3** Use `camelCase` (initial lowercase letter) for function, method, property, constant, variable, argument names, enum cases, etc.
176
176
177
177
***2.4** When dealing with an acronym or other name that is usually written in all caps, actually use all caps in any names that use this in code. The exception is if this word is at the start of a name that needs to start with lowercase - in this case, use all lowercase for the acronym.
178
178
@@ -187,27 +187,26 @@ class URLFinder {
187
187
}
188
188
```
189
189
190
-
***2.5** All constants other than singletons that are instance-independent should be `static`. All such `static` constants should be placed in a container `enum` type as per rule **3.1.16**. The naming of this container should be singular (e.g. `Constant` and not `Constants`) and it should be named such that it is relatively obvious that it is a constant container. If this is not obvious, you can add a `Constant` suffix to the name. You should use these containers to group constants that have similar or the same prefixes, suffixes and/or use cases.
190
+
***2.5** All constants that are instance-independent should be `static`. All such `static` constants should be placed in a marked section of their `class`, `struct`, or `enum`. For classes with many constants, you should group constants that have similar or the same prefixes, suffixes and/or use cases.
191
191
192
192
```swift
193
+
// PREFERRED
193
194
classMyClassName {
194
-
// PREFERRED
195
-
enumMeasurement {
196
-
staticlet buttonPadding: CGFloat =20.0
197
-
}
198
-
enumSillyMathConstant {
199
-
staticlet indianaPi =3
200
-
}
195
+
// MARK: - Constants
196
+
staticlet buttonPadding: CGFloat =20.0
197
+
staticlet indianaPi =3
201
198
staticlet shared =MyClassName()
199
+
}
202
200
203
-
// NOT PREFERRED
201
+
// NOT PREFERRED
202
+
classMyClassName {
203
+
// Don't use `k`-prefix
204
204
staticlet kButtonPadding: CGFloat =20.0
205
-
enumSillyMath {
205
+
206
+
// Don't namespace constants
207
+
enumConstant {
206
208
staticlet indianaPi =3
207
209
}
208
-
enumSingleton {
209
-
staticlet shared =MyClassName()
210
-
}
211
210
}
212
211
```
213
212
@@ -479,8 +478,6 @@ do {
479
478
480
479
***3.1.15** If you have a function that takes no arguments, has no side effects, and returns some object or value, prefer using a computed property instead.
481
480
482
-
***3.1.16** For the purpose of namespacing a set of `static` functions and/or `static` properties, prefer using a caseless `enum` over a `class` or a `struct`. This way, you don't have to add a `private init() { }` to the container.
483
-
484
481
### 3.2 Access Modifiers
485
482
486
483
***3.2.1** Write the access modifier keyword first if it is needed.
0 commit comments