Apple's recommended folder structure and architectural patterns for SwiftUI applications based on official sample projects
Apple’s fundamental SwiftUI architecture revolves around three building blocks:
1. App Protocol
@main
attribute to mark the app’s entry point2. Scene Protocol
WindowGroup
for standard appsDocumentGroup
for document-based apps and Settings
for macOS preferences3. View Protocol
Based on Apple’s sample projects (Backyard Birds and Food Truck), here’s the recommended structure:
MyApp/
├── MyApp.swift # App entry point with @main
├── ContentView.swift # Main content view
├── Assets.xcassets # Image and color assets
├── Info.plist # App configuration
├── Features/ # Feature-based organization
│ ├── Home/
│ │ ├── HomeView.swift
│ │ ├── HomeViewModel.swift # If using MVVM
│ │ └── Components/
│ ├── Profile/
│ │ ├── ProfileView.swift
│ │ └── ProfileEditView.swift
│ └── Settings/
├── Models/ # Data models
│ ├── User.swift
│ └── AppData.swift
├── Services/ # Network, persistence, etc.
│ ├── NetworkService.swift
│ └── DataStore.swift
├── Shared/ # Reusable components
│ ├── Views/
│ ├── Modifiers/
│ └── Extensions/
└── Resources/ # Additional resources
For apps targeting multiple platforms, Apple demonstrates this approach in their Food Truck sample:
MyApp/
├── Multiplatform/ # Shared code across platforms
│ ├── MyApp.swift
│ ├── Navigation/
│ ├── Features/
│ └── Assets.xcassets
├── MyAppKit/ # Reusable framework/package
│ └── Sources/
│ ├── Models/
│ ├── Services/
│ └── Extensions/
├── Widgets/ # Widget extension
└── WatchApp/ # watchOS app
Apple’s SwiftUI samples demonstrate a simplified architecture where:
@Observable
(iOS 17+) or ObservableObject
@State
, @StateObject
, and @Binding
@State
for view-local state@StateObject
for reference type ownership@ObservedObject
for observing external objects@EnvironmentObject
for dependency injectionGroup files by feature rather than by type (views, models, etc.) to improve discoverability and maintainability.
Both sample apps demonstrate using Swift Package Manager for shared code:
BackyardBirdsData
- Data layer packageBackyardBirdsUI
- UI components packageFoodTruckKit
- Shared business logicUse conditional compilation and platform-specific folders when needed:
#if os(iOS)
// iOS-specific code
#elseif os(macOS)
// macOS-specific code
#endif
Here’s a minimal example following Apple’s pattern:
// MyApp.swift
@main
struct MyApp: App {
@StateObject private var dataStore = DataStore()
var body: some Scene {
WindowGroup {
ContentView()
.environmentObject(dataStore)
}
}
}
// Models/DataStore.swift
@MainActor
class DataStore: ObservableObject {
@Published var items: [Item] = []
func loadData() async {
// Load data
}
}
// Features/Home/HomeView.swift
struct HomeView: View {
@EnvironmentObject var dataStore: DataStore
var body: some View {
NavigationStack {
List(dataStore.items) { item in
ItemRow(item: item)
}
}
.task {
await dataStore.loadData()
}
}
}
Traditional MVC/MVVM:
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Model │◄──►│ View Model │◄──►│ View │
└─────────────┘ └─────────────┘ └─────────────┘
SwiftUI MV Pattern:
┌─────────────┐ ┌─────────────┐
│ @Observable │◄──►│ View │
│ Model │ │ (SwiftUI) │
└─────────────┘ └─────────────┘
Organize by user-facing features rather than technical layers:
Features/
├── Authentication/
│ ├── LoginView.swift
│ ├── SignUpView.swift
│ └── AuthenticationService.swift
├── Dashboard/
│ ├── DashboardView.swift
│ ├── DashboardViewModel.swift
│ └── Components/
│ ├── MetricCard.swift
│ └── ChartView.swift
└── Settings/
├── SettingsView.swift
└── PreferencesStore.swift
Create reusable UI components:
Shared/
├── Views/
│ ├── CustomButton.swift
│ ├── LoadingView.swift
│ └── ErrorView.swift
├── Modifiers/
│ ├── CardStyle.swift
│ └── AnimationModifiers.swift
└── Extensions/
├── View+Extensions.swift
└── Color+Theme.swift
Mirror your main structure in tests:
Tests/
├── UnitTests/
│ ├── Models/
│ ├── Services/
│ └── ViewModels/
├── UITests/
│ ├── Features/
│ └── Flows/
└── TestUtilities/
├── MockData.swift
└── TestHelpers.swift
Apple’s recommended structure emphasizes:
Apple’s recommended structure emphasizes simplicity, feature-based organization, and leveraging SwiftUI’s built-in state management rather than imposing complex architectural patterns. The key is to start simple and add complexity only when needed, keeping your code organized by features and making use of Swift packages for reusable components.
This approach aligns perfectly with SwiftUI’s declarative nature and Apple’s design philosophy of making development more intuitive and maintainable.
SwiftUI App Structure
https://developer.apple.com/documentation/swiftui/app
WWDC 2020: SwiftUI App Structure
https://developer.apple.com/videos/play/wwdc2020/10037/
Building Large Scale Apps with SwiftUI
https://azamsharp.com/2023/02/28/building-large-scale-apps-swiftui.html
SwiftUI Architecture: Complete Guide to MV Pattern
https://betterprogramming.pub/swiftui-architecture-a-complete-guide-to-mv-pattern-approach-5f411eaaaf9e
SwiftUI Architecture Guide
https://www.swiftyjourney.com/swiftui-architecture-a-complete-guide-to-the-mv-pattern-approach
SwiftUI Data Flow (YouTube)
https://www.youtube.com/watch?v=V2yKZHrXRYA
Managing User Interface State
https://developer.apple.com/documentation/swiftui/managing-user-interface-state
SwiftUI Documentation
https://developer.apple.com/documentation/SwiftUI
Exploring SwiftUI App Structure
https://developer.apple.com/tutorials/swiftui-concepts/exploring-the-structure-of-a-swiftui-app
SwiftUI Tutorials
https://developer.apple.com/tutorials/swiftui/
SwiftUI App Organization
https://developer.apple.com/documentation/swiftui/app-organization
SwiftUI Get Started
https://developer.apple.com/swiftui/get-started/
iOS Project Standards
https://github.com/BottleRocketStudios/iOS-Project-Standards/blob/main/Project%20Structure/Project%20Structure.md
Xcode Project Structure (YouTube)
https://www.youtube.com/watch?v=E3DOCoZ7oH8
Xcode Project Groups Best Practice
https://stackoverflow.com/questions/39945727/best-practice-for-an-xcode-project-groups-structure
SwiftUI Official Architecture Discussion
https://forums.swift.org/t/what-is-the-architecture-officially-recommended-by-apple-for-swiftui-applications/44930
WWDC 2020: Data Essentials in SwiftUI
https://developer.apple.com/videos/play/wwdc2020/10040/
SwiftUI Scene Documentation
https://developer.apple.com/documentation/swiftui/scene
Nice Architecture for SwiftUI
https://steamclock.com/blog/2024/04/nice-architecture
MVVM in SwiftUI
https://www.avanderlee.com/swiftui/mvvm-architectural-coding-pattern-to-structure-views/
MV State Pattern Introduction
https://azamsharp.com/2022/08/09/intro-to-mv-state-pattern.html
WWDC 2024: SwiftUI Essentials
https://developer.apple.com/videos/play/wwdc2024/10150/
Backyard Birds Sample Project
https://developer.apple.com/documentation/swiftui/backyard-birds-sample
Backyard Birds GitHub
https://github.com/apple/sample-backyard-birds
Food Truck Sample Project
https://developer.apple.com/documentation/swiftui/food_truck_building_a_swiftui_multiplatform_app
Food Truck GitHub
https://github.com/apple/sample-food-truck