无法将类型 'String' 的值转换为预期的参数类型“[Any]”

Cannot convert value of type 'String' to expected argument type '[Any]'

我在 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 值,因此我不确定如何解决此错误。

我很感激任何 help/guidance!

arrayRemove 接受一组要删除的值,你想使用:

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

见加括号

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

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