简体   繁体   中英

"Cannot convert value of type 'String' to expected argument type '[Any]'" error when trying to add array element in firestore in swift app

when trying to add an element to an existing array in firestore I get the error "Cannot convert value of type 'String' to expected argument type '[Any]'"

this is the method where the error occurs:

func addEventIdToUser(eventID: String) async {
        let db = Firestore.firestore()
        let userReference = try await db.collection("user").document(userID)
        try? await userReference.updateData(["events": FieldValue.arrayUnion(eventID)])
  
    }

does anyone know how to solve the issue?

SOLUTION:

I forgot brackets around eventID

this is the right way:

  try? await userReference.updateData(["events": FieldValue.arrayUnion([eventID])])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM