Swift Binding Fixer

VerifiedSafe

Fixes SwiftUI '$' binding errors ('cannot find $viewModel') by replacing @State or plain properties with @Bindable on @Observable ViewModels in the Leavn app. Use this when encountering sheet presentation or other binding errors in SwiftUI views.

Sby Skills Guide Bot
DevelopmentIntermediate
1006/2/2026
Claude Code
#swift#swiftui#binding#observable#fix

Recommended for

Our review

Fixes SwiftUI binding errors caused by missing @Bindable attribute on @Observable view models.

Strengths

  • Quickly resolves common '$viewModel' compile errors in SwiftUI.
  • Provides specific patterns for common view models (Home, Community, etc.).
  • Uses grep to locate error and then edits file programmatically.

Limitations

  • Only works when the error is specifically 'cannot find $viewModel' - does not handle other binding errors.
  • Assumes the view model is already @Observable; will not work if it's not.
  • May require manual adjustment if the view model needs to remain @State for other reasons.
When to use it

Use this skill when you encounter a SwiftUI compile error 'cannot find $viewModel' and the view model is an @Observable class or struct.

When not to use it

Do not use this skill for other SwiftUI binding errors or when the view model is not declared with @Observable.

Security analysis

Safe
Quality score85/100

The skill only uses safe tools (Read, Edit, Grep) for local code editing tasks. No network access, destructive commands, or data exfiltration risk.

No concerns found

Examples

Fix home sheet binding
Fix the 'cannot find $viewModel' error in HomeView - it uses HomeViewModel and a sheet.
Fix community creation binding
The CommunityView has a $viewModel error for showing the create community sheet. Fix it by adding @Bindable.

name: swift-binding-fixer description: Fix SwiftUI binding errors ($var issues) by adding @Bindable to @Observable ViewModels in Leavn app allowed-tools: Read, Edit, Grep disable-model-invocation: false context: fork user-invocable: true argument-hint: "[context]"

Swift Binding Fixer

Instructions

Fix "cannot find '$viewModel'" errors:

  1. Find the error:

    grep "cannot find '\$viewModel'" build_output.txt
    
  2. Read the view file:

    • Check if viewModel is @Observable type
    • Look for @State var viewModel or var viewModel
    • Find all $viewModel.property usages
  3. Apply fix:

    // BEFORE
    @State var viewModel: MyViewModel
    // OR
    var viewModel: MyViewModel
    
    // AFTER (if using $viewModel)
    @Bindable var viewModel: MyViewModel
    
  4. Common Leavn patterns:

    • HomeViewModel: Use @Bindable for sheet bindings
    • CommunityViewModel: Use @Bindable for showCreate* bindings
    • SettingsViewModel: Use @Bindable for alert bindings
    • SermonAIView: Use @Bindable for showing* bindings

Use this skill when: $viewModel errors, @Observable binding issues, sheet presentation errors

Related skills