Cannot find 'x' in scope iOS Origin: On your device OSI layer 7 · Application Last updated 25 Nov 2026

error: Cannot find 'viewModel' in scope

The name isn't visible where you use it.

Exact message you may see Cannot find in scopecannot find type in scopeCannot find 'viewModel' in scopeerror: cannot find 'viewModel' in scope
Seen on: iOS Swift

Meaning

Typo, missing import, wrong access level, variable declared in another scope, or a file not in the target. Check spelling and target membership.

Common causes

  • Missing import
  • Identifier typo
  • File not in target

⚡ Quick fix

  1. Add the right import
  2. Check target membership of the file
  3. Fix the name or access level

Detailed fix by platform

Swift

  1. swift
    import SwiftUI
    import Combine

How to diagnose

  1. Import — present?
  2. Target — includes file?
  3. Scope — visible?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: On your device. Errors that are often confused with or caused by this one (click to open):

'init' is inaccessible due to 'private' protection level — error: 'init' is inaccessible due to 'internal' protection level (iOS)'init' is inaccessibl…'nil' requires a contextual type / Cannot infer type — error: 'nil' requires a contextual type (iOS)'nil' requires a cont…Ambiguous use of 'init' / trailing closure — error: ambiguous use of 'init(content:)' (iOS)Ambiguous use of 'ini…Argument of '#selector' refers to instance method that is not exposed to Objective-C — error: argument of '#selector' refers to instance method 'tap()' that is not exposed to Objective-C (iOS)Argument of '#selecto…Cannot convert value of type — Swift: Cannot convert value of type 'X' to expected argument type 'Y' (iOS)Cannot convert value …Cannot use instance member as a default parameter — error: cannot use instance member 'x' as a default parameter (iOS)Cannot use instance m…Core ML: failed to load model / compile — Error Domain=com.apple.CoreML Code=0 "Unable to load model: file:///.../Model.mlmodelc" (iOS)Core ML: failed to lo…Could not cast value of type — Swift: Could not cast value of type 'X' to 'Y' (iOS)Could not cast value …Cannot fi…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.