Closed
Description
[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
struct User: Codable {
@DocumentID var id: String?
var name: String
var imageURL: URL?
var location: String?
@ServerTimestamp var createdAt: Date?
@ServerTimestamp var updatedAt: Date?
}
let user = User(name: "Matthew")
user.id = "ANYTHING"
let ref = Firestore.firestore().collection("users").document(userId)
try! ref.setData(from: self)