Code Style Guide
These conventions keep TablePro’s codebase consistent and readable.Tools
| Tool | Purpose | Config File |
|---|---|---|
| SwiftLint | Linting and static analysis | .swiftlint.yml |
| SwiftFormat | Code formatting | .swiftformat |
Running Tools
Architecture Principles
Separation of Concerns: Logic in viewmodels, presentation in views. Value Types First: Usestruct for data, class for shared state.
Immutability: Default to let; use var only when mutation is needed.
Naming Conventions
Types
| Element | Convention | Example |
|---|---|---|
| Classes/Structs | UpperCamelCase | DatabaseConnection |
| Enums | UpperCamelCase | DatabaseType |
| Enum cases | lowerCamelCase | .postgresql |
| Protocols | UpperCamelCase | DatabaseDriver |
Functions and Variables
| Element | Convention | Example |
|---|---|---|
| Functions | lowerCamelCase | executeQuery() |
| Variables | lowerCamelCase | connectionString |
| Constants | lowerCamelCase | maxRetryAttempts |
| Parameters | lowerCamelCase | tableName: String |
Boolean Properties
Useis/has/can prefixes:
Factory Methods
Usemake prefix:
Formatting
Indentation
- 4 spaces (never tabs)
- Configure your editor to convert tabs to spaces
Line Length
- 120 characters max per line
- Break long lines for readability
Braces
K&R style — opening brace on same line:Spacing
Access Control
Specify Explicitly
Always specify access modifiers:Prefer Private
Use the most restrictive access that works:Extension Access
Specify access on the extension, not individual members:Optionals & Safety
Never force unwrap. Useif let, guard let, or as? for safe optional handling.
SwiftUI Patterns
Use @StateObject for viewmodels, @State for local state. Order property wrappers: Environment, StateObject, State, Binding, regular properties. Extract large views into subviews.Limits
SwiftLint Limits
| Metric | Warning | Error |
|---|---|---|
| Function body length | 160 lines | 250 lines |
| Type body length | 1100 lines | 1500 lines |
| File length | 1200 lines | 1800 lines |
| Cyclomatic complexity | 40 | 60 |
Handling Long Files
Extract extensions into separate files:MainContentCoordinator.swift
Extensions
MainContentCoordinator+RowOperations.swift
MainContentCoordinator+Pagination.swift
MainContentCoordinator+Filtering.swift
