Use when you work with Swift code or Xcode tooling - establishes style guidelines, teaches you vital Swift techniques, and how to use Xcode build tools
2 spaces, no tabs.
If a comment contains documentation or explanation, it must use a triple slash
(///), regardless of its position in the source code.
Use double slash comments (//) only for Xcode directive comments ("MARK:",
"TODO:", etc.) and for temporarily disabling blocks of code. You must never use
double slash (//) for documentation comments.
guard clausesguard clauses must be written multi-line. If a clause combines multiple
conditions, each condition must be on its own line.
// ❌ Bad
guard somethingCondition else { return }
// ✅ Good
guard somethingCondition else {
return
}
// ❌ Bad
guard !somethingCondition1, let something else { return }
// ✅ Good
guard !somethingCondition1,
let something
else {
return
}
Any guard clause must be followed by a blank line.
if blocksif clauses must be written multi-line. If a clause combines multiple
conditions, each condition should be on its own line. If there is more than one
condition, the opening bracket ({) should be on its own line.
// ❌ Bad
if !somethingCondition1, let something {
return
}
// ✅ Good
if !somethingCondition1,
let something
{
return
}
switch/caseEvery case block must be followed by a blank line.
Write idiomatic SwiftUI code following Apple's latest architectural recommendations and best practices.
For simple use cases that don't contain a lot of logic and state, use SwiftUI's built-in property wrappers appropriately:
@State - Local, ephemeral view state@Binding - Two-way data flow between views@Observable - Shared state (iOS 17+)@ObservableObject - Legacy shared state (pre-iOS 17)@Environment - Dependency injection for app-wide concernsFor more complex use cases with lots of logic and interdependent states, use Composable Architecture. Before starting to write code, read the TCA documentation (see section "Read SDK/ package/ library/ framework documentation").
async/await as the default for asynchronous operations.task modifier for lifecycle-aware async workstruct CounterView: View {
@State private var count = 0
var body: some View {
VStack {
Text("Count: \(count)")
Button("Increment") {
count += 1
}
}
}
}
@Observable
class UserSession {
var isAuthenticated = false
var currentUser: User?
func signIn(user: User) {
currentUser = user
isAuthenticated = true
}
}
struct MyApp: App {
@State private var session = UserSession()
var body: some Scene {
WindowGroup {
ContentView()
.environment(session)
}
}
}
struct ProfileView: View {
@State private var profile: Profile?
@State private var isLoading = false
@State private var error: Error?
var body: some View {
Group {
if isLoading {
ProgressView()
} else if let profile {
ProfileContent(profile: profile)
} else if let error {
ErrorView(error: error)
}
}
.task {
await loadProfile()
}
}
private func loadProfile() async {
isLoading = true
defer { isLoading = false }
do {
profile = try await ProfileService.fetch()
} catch {
self.error = error
}
}
}
Write SwiftUI code that looks and feels like SwiftUI. The framework has matured significantly - trust its patterns and tools. Focus on solving user problems rather than implementing architectural patterns from other platforms.
Pipe xcodebuild output directly to xcsift to get clean, readable results for
use by LLM:
xcodebuild [flags] 2>&1 | xcsift
Important: Always use 2>&1 to redirect STDERR to STDOUT. This ensures all
compiler errors, warnings, and build output are captured, removing noise and
providing clean, structured JSON output.