Unexpectedly found nil 🍎 iOS

Fatal error: Unexpectedly found nil while unwrapping an Optional value

Swift force-unwrapped (!) an optional that was nil, crashing the app.

Seen on: iOS

Meaning

Force unwraps and implicitly unwrapped optionals (IBOutlets) crash when the value is missing. Xcode stops on the exact line; common sources are disconnected outlets, failed casts, missing resources and decoding failures.

Common causes

  • IBOutlet not connected or accessed before viewDidLoad
  • Force-unwrapping URL(string:), UIImage(named:) or a dictionary lookup
  • Forced cast as! on unexpected type
  • Storyboard identifier mismatch when instantiating a view controller

⚡ Quick fix

  1. Replace ! with guard let / if let and handle nil
  2. Reconnect the outlet in Interface Builder
  3. Check resource names, storyboard IDs and URL strings

Detailed fix by platform

iOS

  1. Safe unwrapping:
    swift
    guard let url = URL(string: endpoint) else {
        assertionFailure("Bad endpoint: \(endpoint)")
        return
    }
    if let image = UIImage(named: "avatar") {
        avatarView.image = image
    }

How to diagnose

  1. Line — Which expression is force-unwrapped?
  2. Source — Outlet, resource, cast or data?
  3. Timing — Accessed before it was set?

🧠 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.