Build SwiftUI views with state management and navigation
✓Works with OpenClaudeYou are a SwiftUI developer building production iOS apps. The user wants to create SwiftUI views with proper state management (@State, @ObservedObject, @EnvironmentObject) and implement navigation patterns (NavigationStack, NavigationLink).
What to check first
- Verify Xcode version supports SwiftUI (iOS 13.0+, macOS 10.15+, or later for NavigationStack)
- Check your target's minimum deployment target in Build Settings — SwiftUI requires iOS 13.0 minimum
- For NavigationStack, ensure your project targets iOS 16.0+ or macOS 13.0+
Steps
- Define your data model as a class conforming to
ObservableObjectwith@Publishedproperties for reactive updates - Create your primary view as a
structconforming toViewwith abodyproperty returningsome View - Use
@Statefor simple local state that's owned and managed by a single view - Use
@ObservedObjector@StateObjectto reference external ObservableObject instances - Implement
@EnvironmentObjectto share data across your view hierarchy without passing through every view - Use
NavigationStack(iOS 16+) withnavigationDestination(for:destination:)for type-safe navigation, orNavigationLinkfor direct navigation - Manage navigation state with a dedicated
@Statevariable or property in your navigation coordinator - Test navigation with Xcode Previews using
#Previewmacro, providing mock data via environment or state
Code
import SwiftUI
// MARK: - Data Model
class UserViewModel: ObservableObject {
@Published var users: [User] = []
@Published var selectedUser: User?
@Published var isLoading = false
func fetchUsers() {
isLoading = true
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
self.users = [
User(id: 1, name: "Alice", email: "alice@example.com"),
User(id: 2, name: "Bob", email: "bob@example.com")
]
self.isLoading = false
}
}
}
struct User: Identifiable, Hashable {
let id: Int
let name: String
let email: String
}
// MARK: - Main Navigation View
struct ContentView: View {
@StateObject private var viewModel = UserViewModel()
var body: some View {
NavigationStack {
ZStack {
if viewModel.isLoading {
ProgressView()
} else {
UserListView(viewModel: viewModel)
}
}
.navigationTitle("Users")
.onAppear {
viewModel.fetchUsers()
}
}
}
}
// MARK: - List View
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Swift / iOS Skills
Other Claude Code skills in the same category — free to download.
UIKit
Create UIKit view controllers with Auto Layout
Core Data
Set up Core Data with models, contexts, and fetch requests
Swift Networking
Build networking layer with URLSession and Codable
Swift Combine
Use Combine for reactive programming in Swift
Swift Testing
Write XCTest unit and UI tests for iOS apps
Swift Async/Await Concurrency
Use Swift's structured concurrency for async code without callback hell
Swift CoreData Relationships
Model one-to-many and many-to-many relationships in CoreData
Want a Swift / iOS skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.