Firebase Android library has Exclude annotation which allows to ignore a property when saving/retrieving object to and from database.
Is there a similar property wrapper for Swift FirebaseFirestoreSwift
library?
As far as I can see DocumentId annotation has equivalent property wrapper in Swift library.
What is the best way to exclude property from database in Codable
object in Swift anyway?
2
Answers
I've created such wrapper. It makes code more concise. It indeed deals with
Codable
, and should work fine with Firebase Coder as good as with any other one (such as JSONEncoder/Decoder). Let me modestly present@CodableExcluded
Usage
Using
CodingKeys
is the default mechanism to fine-tune Codable’s mapping. If you’re interested in how Codable works in general, check out this excellent book: Flight School Guide to Swift Codable and this Hacking with Swift article: Codable cheat sheet – Hacking with Swift.The Firebase documentation has a comprehensive guide for using Codable with Firestore: Map Cloud Firestore data with Swift Codable, which talks about customising the mapping in this section:
If you find anything missing in this guide, please let us know so we can add it.