【问题标题】:Cannot convert value of type 'String' to expected argument type '[Any]'无法将“String”类型的值转换为预期的参数类型“[Any]”
【发布时间】:2021-06-18 14:32:24
【问题描述】:

我在cellForRowAt 方法中收到以下代码的错误:

self.db.collection("myCollection").document(self.currentUser!).updateData(["myArray":FieldValue.arrayRemove(myArray![indexPath.row])]).

Cannot convert value of type 'String' to expected argument type '[Any]' 错误发生在myArray![indexPath.row]

我的函数旨在从myArray 中删除String 值,因此我不确定如何解决此错误。

感谢任何帮助/指导!

【问题讨论】:

    标签: ios arrays swift database uitableview


    【解决方案1】:

    arrayRemove 需要一个要删除的值数组,您想使用:

    .arrayRemove([myArray![indexPath.row]])
    

    查看添加的括号

    (https://firebase.google.com/docs/firestore/manage-data/add-data#update_elements_in_an_array)

    话虽如此,请注意您正在使用! 强制解包多个内容——请注意,如果这些值之一是nil,您的程序将会崩溃。

    【讨论】:

    • 就是这样!谢谢!!
    猜你喜欢
    • 2020-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多