Code Formatting Guidelines
This document outlines the code formatting standards for Swift and Objective-C code in the SideStore project. Consistent formatting makes the codebase more readable and maintainable.
General Principles
- Consistency: Follow the existing code style in the project
- Readability: Code should be easy to read and understand
- Simplicity: Prefer simple, clear solutions over clever ones
- Apple conventions: Follow Apple's official Swift and Objective-C conventions where possible
Swift Formatting
Naming Conventions
Variables and Functions
- Use camelCase for variables, functions, and methods
- Use descriptive names that clearly indicate purpose
// ✅ Good
let downloadProgress: Float
func validateUserCredentials() -> Bool
var isAppInstalling: Bool
// ❌ Bad
let dp: Float
func validate() -> Bool
var installing: Bool
Classes, Structs, Enums, and Protocols
- Use PascalCase for types
- Use descriptive, noun-based names
// ✅ Good
class AppInstaller
struct InstallationProgress
enum AppState
protocol AppManaging
// ❌ Bad
class installer
struct progress
enum state
protocol managing
Constants
- Use camelCase for constants
- Consider using SCREAMING_SNAKE_CASE for global constants
// ✅ Good
let maxRetryAttempts = 3
private let defaultTimeout: TimeInterval = 30.0
// Global constants
let MAX_CONCURRENT_DOWNLOADS = 5
// ❌ Bad
let MaxRetryAttempts = 3
let max_retry_attempts = 3
Indentation and Spacing
Indentation
- Use 4 spaces for indentation (not tabs)
- Align continuation lines with the opening delimiter
// ✅ Good
func installApp(withIdentifier identifier: String,
sourceURL: URL,
completion: @escaping (Result<Void, Error>) -> Void) {
// Implementation
}
// ❌ Bad
func installApp(withIdentifier identifier: String,
sourceURL: URL,
completion: @escaping (Result<Void, Error>) -> Void) {
// Implementation
}
Line Length
- Keep lines under 120 characters when possible
- Break long lines at logical points
// ✅ Good
let longVariableName = SomeClass.createInstanceWithVeryLongMethodName(
parameter1: value1,
parameter2: value2
)
// ❌ Bad
let longVariableName = SomeClass.createInstanceWithVeryLongMethodName(parameter1: value1, parameter2: value2, parameter3: value3)