簡體   English   中英

無法將“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]

我的 function 是為了從myArray中刪除一個String值,所以我不知道如何解決這個錯誤。

我感謝任何幫助/指導!

arrayRemove需要一個要刪除的值數組,你想使用:

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

請參閱添加的括號

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

話雖如此,請注意您正在使用! -- 請注意,如果這些值之一是nil ,您的程序將崩潰。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM