Run 2 TransitionBlocks in Swift (Firebase)

我是研究僧i 提交于 2020-01-03 03:18:05

问题


My app currently uses Firebase as its backend. Currently, I'm using a transitionBlock to updated a value in my database. I'd like to run another transitionBlock after the first one finishes.

Any idea how to do this?

Code:

 self.ref.child("blah").child(codeSelected).runTransactionBlock({ (currentData: FIRMutableData) -> FIRTransactionResult in
 if var post = currentData.value as? [String : AnyObject], let uid = FIRAuth.auth()?.currentUser?.uid {

            print(post)
            var totalCount = post["total"] as? Int ?? 0
            var usersList = post["users"] as? [String] ?? []



            totalCount += 1
            usersList.append(uid)

            post["total"] = totalCount
            post["users"] = usersList
            currentData.value = post

            print("Updated Blah")
            self.updateUserValues() //This is where I'm calling the function for my second transitionBlock*
            return FIRTransac tionResult.successWithValue(currentData)
        }
        return FIRTransactionResult.successWithValue(currentData)
    }) { (error, committed, snapshot) in


        if let error = error {
            print(error.localizedDescription)
        }
    }

The second transition is very similar to the first one, it just has a different ref.

来源:https://stackoverflow.com/questions/37738144/run-2-transitionblocks-in-swift-firebase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!