SwiftUI – Initializer 'init(_:)' requires that 'Binding<Int>' conform to 'LosslessStringConvertible'

huangapple go评论71阅读模式
英文:

SwiftUI - Initializer 'init(_:)' requires that 'Binding<Int>' conform to 'LosslessStringConvertible'

问题

我得到了以下翻译:

如果user.hiddenUsersString不包含(String(meme.userid) + ",")

我收到了

Initializer 'init(_:)' 要求 'Binding&lt;Int&gt;' 符合 'LosslessStringConvertible'

对于String的错误信息。

这是什么情况?直到昨天都没有错误。

为什么Swift如此令人头疼:/

英文:
if(!user.hiddenUsersString.contains(String(meme.userid) + &quot;,&quot;)){

}

I get

Initializer &#39;init(_:)&#39; requires that &#39;Binding&lt;Int&gt;&#39; conform to &#39;LosslessStringConvertible&#39;

on String

what the hell is this? It worked without errors until yesterday.

Why is swift such a pile of garbage :/

答案1

得分: -1

你不能将Binding传递给String的初始化方法。你需要传递BindingwrappedValue

String(meme.userid.wrappedValue)

直到昨天为止,这肯定无法以其当前的形式工作。你可能用Binding&lt;Int&gt;替换了Int属性,这就是引入问题的原因。

> 为什么Swift如此糟糕 :/

它并不糟糕。你只是犯了一个错误 SwiftUI – Initializer 'init(_:)' requires that 'Binding<Int>' conform to 'LosslessStringConvertible'

英文:

You can't pass a Binding to a String init. You need to pass the wrappedValue of the Binding instead.

String(meme.userid.wrappedValue)

This definitely couldn't have worked in its current form until yesterday. You probably replaced the Int property with a Binding&lt;Int&gt; and that's what introduced the issue.

> Why is swift such a pile of garbage :/

It isn't. You just made a mistake SwiftUI – Initializer 'init(_:)' requires that 'Binding<Int>' conform to 'LosslessStringConvertible'

huangapple
  • 本文由 发表于 2023年5月22日 22:04:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76307015.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定