Let's combine everything into a small but real app structure (e.g. a notes or product app).
Recommended structure
- Models — Codable, Identifiable data types.
- ViewModels — ObservableObjects holding @Published state and logic.
- Views — small composable SwiftUI views.
- Services — networking/persistence helpers.
@main
struct NotesApp: App {
@StateObject private var store = NotesStore()
var body: some Scene {
WindowGroup {
NavigationStack { NotesListView() }
.environmentObject(store)
}
}
}
Tip: Keep views dumb and small; put logic in view models. This makes the app testable and easy to change.
Summary
A clean SwiftUI app separates Models, ViewModels, Views and Services, shares state via environment objects, and keeps views small. You can now build full SwiftUI apps!