Develop in Swift Best Practices
Comprehensive guide for Swift and SwiftUI app development, extracted from Apple's official Develop in Swift Tutorials. Contains 41 rules across 13 categories, covering Swift fundamentals through app distribution.
When to Apply
Reference these guidelines when:
-
Learning Swift programming language
-
Building SwiftUI views and interfaces
-
Managing state and data flow
-
Working with SwiftData persistence
-
Implementing navigation patterns
-
Adding accessibility and localization
-
Debugging and testing your app
-
Preparing for App Store distribution
Rule Categories by Priority
Priority Category Impact Prefix
1 Swift Language Fundamentals CRITICAL swift-
2 SwiftUI View Basics CRITICAL view-
3 State & Data Flow CRITICAL state-
4 SwiftData & Persistence HIGH data-
5 Navigation & Presentation HIGH nav-
6 Lists & Dynamic Content HIGH list-
7 User Input & Forms MEDIUM-HIGH input-
8 Testing & Quality MEDIUM-HIGH test-
9 Accessibility & Localization MEDIUM-HIGH access-
10 Debugging & Refinement MEDIUM debug-
11 Machine Learning Integration MEDIUM ml-
12 visionOS & Spatial Computing MEDIUM spatial-
13 App Distribution LOW dist-
Quick Reference
- Swift Language Fundamentals (CRITICAL)
-
swift-let-vs-var
-
Use let for constants, var for variables
-
swift-structs-vs-classes
-
Prefer structs over classes
-
swift-camel-case-naming
-
Use camelCase naming convention
-
swift-string-interpolation
-
Use string interpolation for dynamic text
-
swift-functions-clear-names
-
Name functions and parameters for clarity
-
swift-for-in-loops
-
Use for-in loops for collections
-
swift-optionals
-
Handle optionals safely with unwrapping
-
swift-closures
-
Use closures for inline functions
- SwiftUI View Basics (CRITICAL)
-
view-body-some-view
-
Return some View from body property
-
view-vstack-hstack-zstack
-
Use VStack, HStack, ZStack for layout
-
view-modifier-order-matters
-
Apply modifiers in correct order
-
view-custom-properties
-
Use properties to customize views
-
view-preview-macro
-
Use #Preview for live development
-
view-sf-symbols
-
Use SF Symbols for system icons
-
view-colors-system
-
Use system colors for dark mode support
-
view-gradients
-
Apply gradients for visual interest
- State & Data Flow (CRITICAL)
-
state-state-for-local
-
Use @State for view-local value types
-
state-binding-for-two-way
-
Use @Binding for two-way data flow
-
state-observable-for-models
-
Use @Observable for shared model classes
-
state-environment-for-system
-
Use @Environment for system and shared values
- SwiftData & Persistence (HIGH)
-
data-model-macro
-
Use @Model for SwiftData persistence
-
data-query-for-fetching
-
Use @Query to fetch SwiftData models
-
data-model-container
-
Configure modelContainer in app entry point
-
data-relationships
-
Define model relationships with properties
-
data-crud-operations
-
Perform CRUD with modelContext
- Navigation & Presentation (HIGH)
-
nav-navigationstack
-
Use NavigationStack for hierarchical navigation
-
nav-tabview
-
Use TabView for top-level sections
-
nav-sheets
-
Use sheets for modal presentation
- Lists & Dynamic Content (HIGH)
-
list-foreach-identifiable
-
Use List and ForEach with Identifiable data
-
list-swipe-actions
-
Add swipe actions to list rows
- User Input & Forms (MEDIUM-HIGH)
-
input-textfield
-
Use TextField with binding for text input
-
input-buttons-actions
-
Use Button with action closures
-
input-picker-toggle
-
Use Picker and Toggle for selection input
- Testing & Quality (MEDIUM-HIGH)
- test-swift-testing
- Write unit tests with Swift Testing
- Accessibility & Localization (MEDIUM-HIGH)
-
access-accessibility-labels
-
Add accessibility labels to interactive elements
-
access-dynamic-type
-
Support Dynamic Type for all text
- Debugging & Refinement (MEDIUM)
-
debug-breakpoints
-
Use breakpoints to debug code
-
debug-console-output
-
Use debug console for runtime inspection
- Machine Learning Integration (MEDIUM)
- ml-natural-language
- Use Natural Language framework for text analysis
- visionOS & Spatial Computing (MEDIUM)
- spatial-visionos-windows
- Build visionOS apps with windows
- App Distribution (LOW)
- dist-testflight
- Test with TestFlight before release
How to Use
Read individual reference files for detailed explanations and code examples:
-
Section definitions - Category structure and impact levels
-
Rule template - Template for adding new rules
Full Compiled Document
For a complete compiled guide with all rules in a single document, see AGENTS.md.
Reference Files
File Description
AGENTS.md Complete compiled guide with all rules
references/_sections.md Category definitions and ordering
assets/templates/_template.md Template for new rules
metadata.json Version and reference information