-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@DocumentID not populated with custom codable implementation #7242
Comments
I wasn't sure this actually worked, but #7247 shows that this is possible and works. The issue here is an unfortunate sharp edge in the intersection between property wrappers and Codable. In this code, this field does not have the type you think it does: @DocumentID
public var ref: DocumentReference? While this looks like a field with the type The problem here is that Unfortunately, we can't really compensate for this. At the point where you call ref = try container.decodeIfPresent(DocumentReference.self, forKey: .ref) there's no reflective means by which we could determine that you really meant to get the document ID. This is really requesting that the document have a field in it named The solution is to explicitly ask for the ref = try container.decode(DocumentID<DocumentReference>.self, forKey: .ref)
.wrappedValue Also note that your See the linked PR for a working example. |
[REQUIRED] Step 1: Describe your environment
Swift Package Manager
[REQUIRED] Step 2: Describe the problem
I've taken a look into the codable API, which looks really nice! I've watched https://www.youtube.com/watch?v=3-yQeAf3bLE which links to "Encoding and Decoding Custom Types → https://goo.gle/2T1Quic".
However, I haven't found enough resources about how to use
Codable
with:init(from:Decoder
+encode(to:Encoder)
)@DocumentID
property wrapperIf that case is supported, I think it would be great to have some examples of how to use it, if it's not supported, perhaps that should be mentioned somewhere.
Steps to reproduce:
Create a struct with
@DocumentID
,CodingKeys
and implementpublic init(from decoder: Decoder) throws
as well aspublic func encode(to encoder: Encoder) throws
.How is the property decorated with
@DocumentID
supposed to be encoded/decoded? The only way I've been able to figure it out is by getting it from theuserInfo
, which obviously is wrong.Relevant Code
The text was updated successfully, but these errors were encountered: