英文:
SwiftUI - Initializer 'init(_:)' requires that 'Binding<Int>' conform to 'LosslessStringConvertible'
问题
我得到了以下翻译:
如果user.hiddenUsersString
不包含(String(meme.userid) + ",")
,
我收到了
Initializer 'init(_:)' 要求 'Binding<Int>' 符合 'LosslessStringConvertible'
对于String
的错误信息。
这是什么情况?直到昨天都没有错误。
为什么Swift如此令人头疼:/
英文:
if(!user.hiddenUsersString.contains(String(meme.userid) + ",")){
}
I get
Initializer 'init(_:)' requires that 'Binding<Int>' conform to 'LosslessStringConvertible'
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
的初始化方法。你需要传递Binding
的wrappedValue
。
String(meme.userid.wrappedValue)
直到昨天为止,这肯定无法以其当前的形式工作。你可能用Binding<Int>
替换了Int
属性,这就是引入问题的原因。
> 为什么Swift如此糟糕 :/
它并不糟糕。你只是犯了一个错误
英文:
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<Int>
and that's what introduced the issue.
> Why is swift such a pile of garbage :/
It isn't. You just made a mistake
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论