无法将类型"OSLogMessage"的值转换为预期的字典键类型"AnyHashable" [英] cannot convert value of type 'OSLogMessage' to expected dictionary key type 'AnyHashable'

查看:35
本文介绍了无法将类型"OSLogMessage"的值转换为预期的字典键类型"AnyHashable"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行时出现此错误.它可以成功构建,并且在模拟器中一切正常,但是此特定屏幕无法在预览中构建,并且出现此错误.关于如何解决此问题的任何建议都很棒

Getting this error when I run. It builds successfully and everything works perfect in the simulator, but this particular screen won't build in the preview and it's giving this error. Any suggestions on how to fix this would be great

Compiling failed: cannot convert value of type 'OSLogMessage' to expected dictionary key type 'AnyHashable'

error: cannot convert value of type 'OSLogMessage' to expected dictionary key type 'AnyHashable'
        db.collection(__designTimeString("#7729.[3].[7].[1].modifier[0].arg[0].value", fallback: "movies")).document("\(self.movie.id)").updateData([__designTimeString("#7729.[3].[7].[1].modifier[2].arg[0].value.[0].key", fallback: "items"): FieldValue.arrayUnion(self.selections)])

似乎正在引用的代码

func addItems() {
        let db = Firestore.firestore()
        db.collection("movies").document("\(self.movie.id)").updateData(["items": FieldValue.arrayUnion(self.selections)])
    }

更新了更多代码

@State var selections: [String] = []

VStack {
ForEach(viewModel.items.indices, id: \.self) { i in
          HStack {
            Text(viewModel.items[i].name)
            Spacer()
            Button(action: {
                self.selections = [viewModel.items[i].name]
                self.addItems()
                }) {
                    Text("Add")
                    }
                }
          }
   }
   .onAppear() { self.viewModel.fetchData() }

推荐答案

我为遇到此问题的任何人解决了这一问题.下面的代码解决了所有问题

I solved this one for anyone who comes across this. Code below fixed all problems

@State var selection = ""

VStack {
ForEach(viewModel.items.indices, id: \.self) { i in
          HStack {
            Text(viewModel.items[i].name)
            Spacer()
            Button(action: {
                self.selection = viewModel.items[i].name
                self.addItems()
                }) {
                    Text("Add")
                    }
                }
          }
   }
   .onAppear() { self.viewModel.fetchData() }

func addItems() {
        let db = Firestore.firestore()
        db.collection("movies").document("\(self.movie.id)").updateData([AnyHashable("items"): FieldValue.arrayUnion(["\(self.selection)"])])
    }

这篇关于无法将类型"OSLogMessage"的值转换为预期的字典键类型"AnyHashable"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆