# Cannot convert value of type 'Self' to expected argument type 'Binding\<C>'

[SwiftUI](../..) ⟩ [Layout]() ⟩ [Grids](grids) ⟩&#x20;

{% hint style="success" %}
💊 <mark style="color:red;">**解藥**</mark>：

```swift
@ViewBuilder func layoutCells<L: Layout>(with layout: L) -> some View
    where Element == L.Item    // 💊 解藥
{ ... }
```

👉 [StackOverflow](https://stackoverflow.com/a/71153283/5409815)
{% endhint %}

{% tabs %}
{% tab title="💾 程式" %}
```swift
// 2022.02.17
import SwiftUI

// my protocol for laying out subviews
protocol Layout {
    
    // associated types
    associatedtype Item: Identifiable    // item data
    associatedtype ItemView: View        // item view (cell)
    
    // requirements
    func cellSize(for item: Item) -> CGSize                 // cell size
    func cellCenter(for item: Item) -> CGPoint              // cell position
    @ViewBuilder func cellView(for item: Item) -> ItemView  // cell view for item
}

// an extension that I wish I could use the following syntax:
// `items.layoutCells(with: layout)`
extension RandomAccessCollection where Element: Identifiable
{
    @ViewBuilder func layoutCells<L: Layout>(with layout: L) -> some View {
        ForEach(self) { item in                     // ⛔ error
            let size = layout.cellSize(for: item)
            layout.cellView(for: item)
                .frame(width: size.width, height: size.height)
                .position(layout.cellCenter(for: item))
        }
    }
}
```
{% endtab %}

{% tab title="🗣 討論" %}
* [SwiftUI: Cannot convert value of type 'Self' to expected argument type 'Binding'](https://stackoverflow.com/questions/71152798/swiftui-cannot-convert-value-of-type-self-to-expected-argument-type-binding)
{% endtab %}

{% tab title="👥 相關" %}
* I thought it was caused by [one](https://developer.apple.com/documentation/swiftui/foreach/init\(_:content:\)-96gx9) of  [foreach](../grouping/foreach "mention")'s initializers, but no.\
  ( 👉 See:  💊 <mark style="color:red;">**解藥**</mark> above)
* intended to design a [generic-types](../../../swift/type/category/generic-types "mention") protocol to do custom [](<> "mention") for [grids](grids "mention").
{% endtab %}
{% endtabs %}

