/ios-skills:arimunandar--swiftui-patternsfrom ios-skills
Provides modern SwiftUI patterns for iOS 18+ including @Observable macro, NavigationStack, state management, and SOLID view composition.
Ships in ios-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Master modern SwiftUI development with Swift 6 features, @Observable macro, NavigationStack, and architectural patterns that follow SOLID principles.
The @Observable macro is the modern way to create observable state in SwiftUI:
import SwiftUI
@Observable
final class UserViewModel {
var user: User?
var isLoading = false
var errorMessage: String?
private let repository: UserRepositoryProtocol
init(repository: UserRepositoryProtocol) {
self.repository = repository
}
@MainActor
func loadUser(id: String) async {
isLoading = true
defer { isLoading = false }
do {
user = try await repository.fetch(id: id)
} catch {
errorMessage = error.localizedDescription
}
}
}
| Wrapper | Use Case | Scope |
|---|---|---|
@State | View-local primitive state | Single view |
@Binding | Two-way connection to parent state | Parent-child |
@Bindable | Two-way binding to @Observable property | With @Observable |
@Environment | Dependency injection | Environment chain |
@Observable | Shared mutable state (replaces @ObservableObject) | Across views |
@Observable
final class FormViewModel {
var email = ""
var password = ""
var isValid: Bool {
!email.isEmpty && password.count >= 8
}
}
struct LoginForm: View {
@Bindable var viewModel: FormViewModel
var body: some View {
Form {
TextField("Email", text: $viewModel.email)
SecureField("Password", text: $viewModel.password)
Button("Login") { /* ... */ }
.disabled(!viewModel.isValid)
}
}
}
enum AppRoute: Hashable {
case userProfile(User.ID)
case settings
case orderDetail(Order)
case checkout(Cart)
}
struct ContentView: View {
@State private var path = NavigationPath()
var body: some View {
NavigationStack(path: $path) {
HomeView(path: $path)
.navigationDestination(for: AppRoute.self) { route in
destinationView(for: route)
}
}
}
@ViewBuilder
private func destinationView(for route: AppRoute) -> some View {
switch route {
case .userProfile(let userId):
UserProfileView(userId: userId)
case .settings:
SettingsView()
case .orderDetail(let order):
OrderDetailView(order: order)
case .checkout(let cart):
CheckoutView(cart: cart)
}
}
}
struct ProductListView: View {
@Binding var path: NavigationPath
let products: [Product]
var body: some View {
List(products) { product in
Button {
path.append(AppRoute.productDetail(product.id))
} label: {
ProductRow(product: product)
}
}
}
func navigateToCheckout(cart: Cart) {
path.append(AppRoute.checkout(cart))
}
func popToRoot() {
path.removeLast(path.count)
}
}
// BAD: Monolithic view
struct OrderView: View {
let order: Order
var body: some View {
VStack {
// 100+ lines of UI code
}
}
}
// GOOD: Composed from smaller views
struct OrderView: View {
let order: Order
var body: some View {
ScrollView {
VStack(spacing: 16) {
OrderHeaderView(order: order)
OrderItemsSection(items: order.items)
OrderSummaryView(
subtotal: order.subtotal,
tax: order.tax,
total: order.total
)
OrderActionsView(order: order)
}
.padding()
}
}
}
struct Card<Content: View>: View {
let title: String?
@ViewBuilder let content: () -> Content
init(title: String? = nil, @ViewBuilder content: @escaping () -> Content) {
self.title = title
self.content = content
}
var body: some View {
VStack(alignment: .leading, spacing: 12) {
if let title {
Text(title)
.font(.headline)
}
content()
}
.padding()
.background(.regularMaterial)
.clipShape(RoundedRectangle(cornerRadius: 12))
}
}
// Usage
Card(title: "Order Summary") {
LabeledContent("Subtotal", value: order.subtotal.formatted(.currency(code: "USD")))
LabeledContent("Tax", value: order.tax.formatted(.currency(code: "USD")))
Divider()
LabeledContent("Total", value: order.total.formatted(.currency(code: "USD")))
.bold()
}
struct CardModifier: ViewModifier {
let cornerRadius: CGFloat
func body(content: Content) -> some View {
content
.padding()
.background(.regularMaterial)
.clipShape(RoundedRectangle(cornerRadius: cornerRadius))
.shadow(radius: 2)
}
}
extension View {
func cardStyle(cornerRadius: CGFloat = 12) -> some View {
modifier(CardModifier(cornerRadius: cornerRadius))
}
}
// Usage
Text("Hello")
.cardStyle()
Each view should have one reason to change:
// View: Only presentation
struct UserListView: View {
@State private var viewModel: UserListViewModel
var body: some View {
List(viewModel.users) { user in
UserRow(user: user)
}
.task { await viewModel.loadUsers() }
}
}
// ViewModel: Business logic and state
@Observable @MainActor
final class UserListViewModel {
private let service: UserServiceProtocol
var users: [User] = []
init(service: UserServiceProtocol) {
self.service = service
}
func loadUsers() async {
users = (try? await service.fetchAll()) ?? []
}
}
Extend behavior without modifying existing code:
// Base button style
struct PrimaryButtonStyle: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
.padding()
.background(Color.accentColor)
.foregroundStyle(.white)
.clipShape(RoundedRectangle(cornerRadius: 8))
.opacity(configuration.isPressed ? 0.8 : 1)
}
}
// Extended without modifying original
struct LoadingButtonStyle: ButtonStyle {
let isLoading: Bool
func makeBody(configuration: Configuration) -> some View {
HStack {
if isLoading {
ProgressView()
.tint(.white)
}
configuration.label
}
.padding()
.background(Color.accentColor)
.foregroundStyle(.white)
.clipShape(RoundedRectangle(cornerRadius: 8))
.opacity(configuration.isPressed || isLoading ? 0.8 : 1)
}
}
Depend on abstractions via Environment:
// Protocol abstraction
protocol AnalyticsProtocol {
func track(event: String, properties: [String: Any])
}
// Environment key
private struct AnalyticsKey: EnvironmentKey {
static let defaultValue: AnalyticsProtocol = NoOpAnalytics()
}
extension EnvironmentValues {
var analytics: AnalyticsProtocol {
get { self[AnalyticsKey.self] }
set { self[AnalyticsKey.self] = newValue }
}
}
// Usage in view
struct ProductView: View {
@Environment(\.analytics) private var analytics
let product: Product
var body: some View {
Button("Buy") {
analytics.track(event: "purchase", properties: ["product_id": product.id])
}
}
}
// Inject real or mock
ProductView(product: product)
.environment(\.analytics, FirebaseAnalytics()) // Production
.environment(\.analytics, MockAnalytics()) // Testing
// BAD: Expensive computation in body
var body: some View {
let sortedItems = items.sorted { $0.date > $1.date } // Called on every render
List(sortedItems) { item in
ItemRow(item: item)
}
}
// GOOD: Computed outside body or cached
@Observable
final class ItemListViewModel {
var items: [Item] = []
var sortedItems: [Item] {
items.sorted { $0.date > $1.date }
}
}
@Previewable for Previews (iOS 18+)#Preview {
@Previewable @State var count = 0
VStack {
Text("Count: \(count)")
Button("+1") { count += 1 }
}
}
LazyVStack {
ForEach(items) { item in
ItemRow(item: item)
}
}
LazyVGrid(columns: [GridItem(.adaptive(minimum: 150))]) {
ForEach(products) { product in
ProductCard(product: product)
}
}
references/observable-migration.md for ObservableObject to @Observable migration guidereferences/navigation-patterns.md for advanced navigation patternsreferences/mvvm-architecture.md for complete MVVM implementationWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub jordancoin/ios-skills-collection --plugin ios-skills206 skills in this plugin
/aso-appstore-screenshotsGenerate high-converting App Store screenshots by analyzing your app's codebase, discovering core benefits, and creating ASO-optimized screenshot images using Nano Banana Pro./cleanseReview code for readability, then simplify it to be easy to follow and understand. Use this skill when the user wants to simplify code, improve readability, clean up for handoff, make code skimmable, reduce complexity, refactor for clarity, strip boilerplate, prepare code for future maintainers, or make a codebase easier to pick up. Trigger liberally — any request touching readability, simplification, cleanup, or "make this easier to understand" should use this skill. Also trigger when the user says things like "review this", "clean this up", "tidy this", "make this simpler", "reduce complexity", "flatten this", "strip the noise", or "I want to understand this code quickly next time I open it".
/critical-reasoningApply critical rationalist epistemology (Popper, Deutsch) to evaluate reasoning, identify errors, and refine understanding. Use when the user explicitly requests help with reasoning - phrases like "help me think this through", "does this make sense", "any flaws in this", "what am I missing", "critique this", "is this reasoning sound", "stress test this idea", "devil's advocate", or any request to evaluate arguments, identify logical problems, or improve thinking. Also use when errors in reasoning are significant enough to materially affect the user's goals, even if not explicitly requested.2 plugins ship this exact skill · first indexed Sep 10, 2026
Other plugins' skills for the same job