-
Notifications
You must be signed in to change notification settings - Fork 7
Pocket Swift Style Guide
Swift code should generally follow the conventions listed at https://github.com/raywenderlich/swift-style-guide.
Generally, we rely on SwiftLint
to capture and ensure we follow certain Swift style and conventions. There are some rules that do not exist under the SwiftLint
Rule Directory and we would to follow them for our codebase.
If the access level is internal by default, then there is no need to mark it explicitly. In cases where this applies, please remove the internal
keyword.
We should prefix keys with the function / action they're related to. For example, the key below is utilized for search in general, so we use Search
. UPDATE: We have moved the hard coded strings for these keys to UserDefaultsKey.swift
.
class SearchViewModel: ObservableObject {
static let recentSearchesKey = "Search.recentSearches"
As a rule of thumb, we would like to avoid crashing the application and using fatalError
unless the application is unable to function without the piece of code (i.e. Core Data stack initialization). There is no existing rule in the SwiftLint directory, so as engineers let's be mindful when we see the usage of fatalError
and if it is needed.