【问题标题】:'Result of initializer is unused error' in SwiftUISwiftUI 中的“初始化程序的结果是未使用的错误”
【发布时间】:2020-10-16 03:00:42
【问题描述】:

我可以做些什么来修复这个错误?

'ForEach<Data, ID, Content>'初始值设定项的结果未使用

【问题讨论】:

  • Welcome on SO...下次提供您的代码作为代码,而不是图像、链接等,以便有人可以复制/粘贴和修复​​/修改它。

标签: swift swiftui initializer


【解决方案1】:

你的函数必须在签名中有输出,即

func descriptionItem(.. your params here ..) -> some View {
  // your code here
}

【讨论】:

    【解决方案2】:

    谢谢,我好像已经解决了:

    func descriptionItem(myFrom: Int, myTo: Int) -> some View{
        ForEach(myFrom ..< myTo) { item in
            Button(action: {
                self.theDetail = self.mySites[item]
                self.saveData()
                // self.showAlert = true
            }) {
                Text(self.mySites[item])
                    .modifier(ButtonModifier())
            }
            
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2016-01-20
      • 1970-01-01
      • 2021-10-11
      • 2021-01-02
      • 2020-08-14
      • 2022-11-10
      • 1970-01-01
      • 1970-01-01
      • 2020-07-09
      相关资源
      最近更新 更多