Last active
October 24, 2025 07:39
-
-
Save dterekhov/699edd9d5e44de479edba5c289fc255a to your computer and use it in GitHub Desktop.
Same line written styleguide #best-practices #swift-api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ✅ Should be written on the same line (short, lightweight, commonly used) | |
| /// These annotations are short and typically used with a single variable or function. | |
| /// They don’t add much complexity and keep the code concise. | |
| @State private var isLoading = false | |
| @Binding var isPresented: Bool | |
| @ObservedObject var viewModel: MyViewModel | |
| @Environment(\.dismiss) var dismiss | |
| @ViewBuilder var body: some View | |
| @available(iOS 15.0, *) func setup() {} | |
| @discardableResult func perform() -> Int { ... } | |
| // 🚧 Should be written on a separate line (for clarity, especially when combining multiple annotations) | |
| /// These annotations are more semantic or execution-related. | |
| /// Writing them on separate lines improves readability, especially when stacked together. | |
| @MainActor | |
| @Sendable | |
| func loadData() async { ... } | |
| @MainActor | |
| @Sendable | |
| @escaping | |
| func handleResult(_ result: Result<String, Error>) { ... } | |
| @objc | |
| func buttonTapped() { ... } | |
| @inlinable | |
| public func squared(_ value: Int) -> Int { value * value } | |
| @testable import MyModule |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment