Firebase swift runTransactionBlock:从 'MutableData?' 转换为无关类型 'String' 总是失败

Firebase swift runTransactionBlock : Cast from 'MutableData?' to unrelated type 'String' always fails

我需要 运行 transactionBlock 一个值,而不是 child。

数据结构:

-parent
    - child : value

当我尝试转换从 child 获得的 MutableData 时,我遇到了崩溃。 Xcode 抛出警告确认:

 Cast from 'MutableData?' to unrelated type 'String' always fails

代码片段

Database.database().reference().child("parent").child("child").runTransactionBlock({ (currentData: MutableData!) -> TransactionResult in
                                        
    /**
     *
     * When runTransaction is called, it called straight away doTransaction with a supposed currentData that is the cached value and is often nil the first call.
     * Inside the doTransaction I have to make some actions based to the supposed actual data. Those actions have to work on the new value I want to set for the
     * currentData. Once that is done i send currentData gathered from currentDta.getDtata() which on the first call is just supposed and often nil and the
     * new value that i set with currentData.setData(). If the supposed current value and real current value are the same then I wite the data with the value set
     * in setData() , otherwise I do nothing and I go back with the real value I have in the database in that moment and I repeat.
     *
     *
     */
    
 
    let currentDataValue = currentData.value as! String

根据要求截图如下:

根据官方文档,这应该是可行的:https://firebase.google.com/docs/reference/ios/firebasedatabase/api/reference/Classes/FIRMutableData

正确的做法是什么?找到的所有示例都带有 child [String:Any] 我无法快照从 parent 到 check/write 一条 child.

的数百万条记录

谢谢。

对于遇到相同情况的其他人,请参阅下文