切換語言為:簡體
xcode報錯Initializer ‘init(_:)‘ requires that ‘Binding<String>‘ conform to ‘StringProtocol‘

xcode報錯Initializer ‘init(_:)‘ requires that ‘Binding<String>‘ conform to ‘StringProtocol‘

  • 爱糖宝
  • 2024-07-01
  • 2083
  • 0
  • 0

在使用list展示資料的時候,出錯了:

Cannot assign to property: 'icon' is a 'let' constant

Initializer 'init(_:)' requires that 'Binding<String>' conform to 'StringProtocol'

這是因為前面使用的$foods是Bind型別,所以後麵的food也要是Bind型別,所以就報錯了。

解決辦法:

使用$food進行渲染,就不會報錯了

xcode報錯Initializer ‘init(_:)‘ requires that ‘Binding<String>‘ conform to ‘StringProtocol‘

渲染出來的畫面也正常了:

xcode報錯Initializer ‘init(_:)‘ requires that ‘Binding<String>‘ conform to ‘StringProtocol‘

0則評論

您的電子郵件等資訊不會被公開,以下所有項目均必填

OK! You can skip this field.