# Compiler emits misleading 'Binding' error on \`ForEach\` when its content accesses an optional property inside a complex View

**URL:** <https://forums.swift.org/t/compiler-emits-misleading-binding-error-on-foreach-when-its-content-accesses-an-optional-property-inside-a-complex-view/80502>\
**Category:** Using Swift\
**Tags:** bug, compiler, swiftui\
**Created:** [June 16, 2025, 10:07pm UTC](https://forums.swift.org/t/compiler-emits-misleading-binding-error-on-foreach-when-its-content-accesses-an-optional-property-inside-a-complex-view/80502 "2025-06-16T22:07:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![EdwinZhanCN](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/edwinzhancn/32/41293_2.png) [@EdwinZhanCN](https://forums.swift.org/u/EdwinZhanCN)\
**Post date:** [June 16, 2025, 10:07pm UTC](https://forums.swift.org/t/compiler-emits-misleading-binding-error-on-foreach-when-its-content-accesses-an-optional-property-inside-a-complex-view/80502/1 "2025-06-16T22:07:21Z")

</div>

**1. Description**

The Swift compiler fails to type-check a SwiftUI view when a `ForEach` loop's content includes conditional logic to unwrap an optional property.

The code is **incorrect** , the `Ingredient` struct does not own a `quantity` property, but the compiler produces misleading errors related to `Binding` and generic type inference. The problem is isolated to the `if let...` block inside the `ForEach` loop.

**2. Steps to Reproduce**

1. Set up a project with standard `Identifiable` data models

```swift
import Foundation
import SwiftData
import SwiftUI

@Model
class Ingredient: Identifiable {
    @Attribute(.unique) var id: UUID
    var name: String
    var image: Data?
    
    init(id: UUID = UUID(), name: String, image: Data? = nil) {
        self.id = id
        self.name = name
        self.image = image
    }
}

```

1. Create a parent SwiftUI view like below

2. Inside the parent container, instantiate the following `IngredientsDashboardView`:

3. Attempt to compile the project.

**3. Expected Behavior**

The cmpiler should throw an unwrapping errors.

**4. Actual Behavior**

The build fails with misleading errors pointing to the `ForEach` declaration.

```swift
StepsDetailComponents/StepFullScreenView.swift:396:13 Generic parameter 'C' could not be inferred

StepsDetailComponents/StepFullScreenView.swift:396:21 Cannot convert value of type '[Ingredient]' to expected argument type 'Binding<C>'

StepFullScreenView.swift:402:21 Initializer 'init(_:)' requires that 'Binding<Subject>' conform to 'StringProtocol'

```

**5. Workaround**

None

**6. Environment**

- **Swift version:** `swift-driver version: 1.120.5 Apple Swift version 6.1 (swiftlang-6.1.0.110.21 clang-1700.0.13.3)`
- **Xcode version:** `Version 16.3 (16E140)`
- **OS:** `15.4.1 (24E263)`
