Snippets Collections
    func addPonits(_ fieldName : String, _ points : Int,_ message : String) {
        
        let data = [
            fieldName : FieldValue.increment(Int64(points))
        ]
        
        let db = Firestore.firestore()
        let docRef = db.collection("Games").document(gameID)
        docRef.updateData(data) { error in
            if let error = error {
                print("Error updating document: \(error.localizedDescription)")
            } else {
                print("Document successfully updated")
                self.showToast(message: message)
            }
        }
    }
// Remove item from array

let db = Firestore.firestore()
            db.collection("Products").document("").updateData(["" : FieldValue.arrayRemove(["89024"])])

// increment value             
            db.collection("Products").document("").updateData([
                "field_name" : FieldValue.increment(Int64(3))
                    ])
                    
// union array
                    
            db.collection("collection_name").document("document_id")
            documentRef.updateData([
              "field_name": FieldValue.arrayUnion(["element1", "element2", "element3"])
            ])
star

Fri Mar 31 2023 07:07:52 GMT+0000 (Coordinated Universal Time)

#ios #swift #increment

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension