Skip to content

FirestoreSwift Library: Setting a @DocumentId fails all future saves #9368

Closed
@mknippen

Description

@mknippen

[REQUIRED] Step 1: Describe your environment

  • Xcode version: 13.2.1
  • Firebase SDK version: 8.12.1
  • Installation method: CocoaPods
  • Firebase Component: Firestore Swift
  • Target platform(s): iOS

[REQUIRED] Step 2: Describe the problem

Setting a @documentid fails all future saves. In the FirebaseFirestoreSwift library, there's a property wrapper for the document Id. It's a string, and appears settable. However, doing so causes all subsequent saves to fail with no error message or callback.

Use Case: I want a /users/ table, and I want the key to be their Firebase Auth Id. I create a new User object, set it, and set the Id. However, when I save, nothing happens.

Steps to reproduce:

See Sample code below. Create a user, set the id, and try to save.

Expected Results: It should appear in the database, or return an error message if it fails
Actual Results: Nothing happens. No failure in a do/catch block either

Relevant Code:

import Firebase import FirebaseFirestoreSwift structUser:Codable{@DocumentIDvarid:String?varname:StringvarimageURL:URL?varlocation:String?@ServerTimestampvarcreatedAt:Date?@ServerTimestampvarupdatedAt:Date?}letuser=User(name:"Matthew") user.id ="ANYTHING"letref=Firestore.firestore().collection("users").document(userId)try! ref.setData(from:self)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    close