Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.tablepro.app/llms.txt

Use this file to discover all available pages before exploring further.

Code Style

Tools

.swiftlint.yml and .swiftformat are the source of truth. When in doubt, check those files.
# Check for issues
swiftlint lint

# Auto-fix
swiftlint --fix

# Format all code
swiftformat .

# Check formatting without applying
swiftformat --lint .
SwiftLint also runs during Xcode builds automatically.

Formatting

RuleValue
Indentation4 spaces (never tabs)
Line length120 chars (SwiftLint warns at 180, errors at 300)
BracesK&R (opening brace on same line)
Line endingsLF
SemicolonsNone
Trailing commasNone

Naming

ElementConventionExample
Classes, Structs, Enums, ProtocolsUpperCamelCaseDatabaseConnection
Enum caseslowerCamelCase.postgresql
Functions, Variables, ConstantslowerCamelCaseexecuteQuery(), maxRetryAttempts
Booleansis/has/can prefixisConnected, hasValidCredentials
Factory methodsmake prefixmakeConnection()
AcronymsTreat as wordsJsonEncoder not JSONEncoder (except SDK types)

Access Control

Always explicit. Prefer the most restrictive level that works.
// Specify on the extension, not individual members
public extension NSEvent {
    var semanticKeyCode: KeyCode? { ... }
}

Imports

System frameworks first (alphabetical), then third-party, then local. Blank line after imports.
import AppKit
import Foundation
import os

import CodeEditSourceEditor

import TableProPluginKit

Safety

No force unwrapping (!) or force casting (as!). Use guard let, if let, as?.
// Good
guard let connection = activeConnection else { return }

// Bad
let connection = activeConnection!

Logging

OSLog only. Never print().
import os

private static let logger = Logger(subsystem: "com.TablePro", category: "DatabaseManager")

Localization

  • String(localized:) for user-facing strings in computed properties, AppKit code, alerts, error descriptions
  • SwiftUI view literals (Text("Save"), Button("Cancel")) auto-localize
  • Do not localize technical terms: font names, database types, SQL keywords, encoding names
  • Never use String(localized:) with string interpolation. Use String(format: String(localized: "Preview %@"), name) instead.

SwiftUI Patterns

  • @State for local view state
  • @Observable for viewmodels (Swift 5.9+)
  • Property wrapper order: Environment, State, Binding, regular properties
  • Extract large views into subviews

Limits

MetricWarningError
File length1200 lines1800 lines
Type body1100 lines1500 lines
Function body160 lines250 lines
Cyclomatic complexity4060
When approaching these limits, extract into extension files:
MainContentCoordinator.swift
Extensions
MainContentCoordinator+RowOperations.swift
MainContentCoordinator+Pagination.swift
MainContentCoordinator+Filtering.swift
Group by domain logic, not arbitrary line counts.