Cannot convert value of type iOS Origin: On your device Last updated 14 Oct 2026

Swift: Cannot convert value of type 'X' to expected argument type 'Y'

The value’s type doesn’t match what the function or property expects.

Exact message you may see Cannot convert value of typeto expected argument typeCannot convert value of type 'String?' to expected argument type 'String'
Seen on: iOS

Meaning

Common with optionals (String? vs String), numeric types (Int vs Double/CGFloat), closures with wrong signatures, and Binding vs value in SwiftUI.

Common causes

  • Optional passed where a non-optional is needed
  • Different numeric types without conversion
  • Closure signature mismatch
  • Passing a value instead of a Binding ($state)

⚡ Quick fix

  1. Unwrap optionals (if let/guard/??)
  2. Convert explicitly: Double(x), CGFloat(y)
  3. Use $ for bindings in SwiftUI

Detailed fix by platform

Swift

  1. swift
    let width: CGFloat = CGFloat(columns) * 44
    Toggle("Notifications", isOn: $settings.enabled)

How to diagnose

  1. Types — Actual vs expected
  2. Context — Optional/numeric/binding?

🔧 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):

Array to string conversion — Warning: Array to string conversion (PHP)Array to string conve…AttributeError — AttributeError: 'X' object has no attribute 'y' (Python)AttributeErrorCannot use object as array — Fatal error: Uncaught Error: Cannot use object of type stdClass as array (PHP)Cannot use object as …ClassCastException — java.lang.ClassCastException: class A cannot be cast to class B (Java)ClassCastExceptionCould not cast value of type — Swift: Could not cast value of type 'X' to 'Y' (iOS)Could not cast value …E0308 — Rust: error[E0308]: mismatched types — expected `X`, found `Y` (Rust)E0308Escaping closure captures mutating 'self' — Swift: Escaping closure captures mutating 'self' parameter (iOS)Escaping closure capt…Implicit float to int — Deprecated: Implicit conversion from float 2.5 to int loses precision (PHP)Implicit float to intCannot co…

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.