-
Notifications
You must be signed in to change notification settings - Fork 91
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
How to map to FIRTimestamp #36
Comments
Struggling with this as well as Firestore has now made the push to |
Thanks, i'll take a look. |
Hey guys! First of all, sorry for being unresponsive lately... I am really glad that there is support from community! About the issue. I think that the proper way to do it, would be to do something similar to here. So we can make FirTimestamp Encodable and it will be skipped and left untouched when encoding and thus will let the Firestore handle it. I will open a PR with an example of how to use it! What do you think about it? |
@alickbass would be great if we get some best practice guidance on that! |
Hey guys! The PR makes Timestamp conform to import CodableFirebase
extension Timestamp: TimestampType {}
struct FirTimestampModel: Codable {
let timestamp: Timestamp
}
let timestamp = FirTimestampModel(timestamp: Timestamp(date: Date()))
let data = try! FirestoreEncoder().encode(timestamp) If you want to use Date in your models and convert to Timestamp on server, I would really discourage that, as then you will lose all the precision. |
Thank you for your effort 👍 |
Thanks @alickbass! Agree to disagree about having Timestamp in your models though. Creating a dependency on Firestore for the Timestamp type at the model layer doesn't feel good to me. |
Well, I think that the reason to use |
Yeah, I would prefer to use
|
Valid point, @dannypier... Maybe I will find a better alternative... I will keep you updated, guys |
@alickbass Right now Firestore is crashing while using Date objects in the model, and I am also not very keen to be using FIRTimestamp in my model objects. It's not a dependency I'd like to have in my project as we might shift from Firestore in the future. Edit: I took an attempt at supporting this. I realized the best way to do it is while encoding a However, to achieve this |
In general, I am okay with adding Firebase as a dependency and removing all the redundant protocols and just working with Firebase / Firestore values. If you guys are willing to contribute, please submit a PR and I would love to review. Unfortunately, I haven't had time lately to submit any code myself |
@alickbass I'll work on it this weekend. I was busy this past week. I'm going to try to do it without actually including Firebase as a dependency, if I am not able I'll just go ahead and add it. |
@serjooo tbh, I would like to add it as a dependency and remove all the weird protocols that we have. |
@alickbass What method do you see best fitting to add Firebase as a dependency? I stumbled upon this issue where things become a little tricky to add Firebase through Cocoapods |
Was this ever solved? @serjooo @alickbass |
@jimijon not yet. We need to add Firebase as a dependency of this project; however, I really had some hard time doing it and never had the time to research and give a shot again, but most probably I'll try to contribute again as I'm thinking of using CodableFirebase again for a future project of mine. |
@serjooo @alickbass any updates on this and/or is there any workaround? |
@alickbass I finally found sometime to work on this today and I included the Do you think its still worth investing more time and doing the same implementation as that PR on Also something to note adding |
I have started working on that PR myself quite some time ago, however, due to change in work could not continue... I am not sure what is their roadmap and timeline is... |
Yes you are right it seems like they keep postponing the release and you can never be sure of what their timeline is. How about you submit a PR of your current work on a separate branch and we can work on it together? |
sorry, I meant the PR on Firebase itself 😂I haven't done anything here yet, so feel free to submit your ideas 😎 |
perfect one . it's woking for me. thank you so much for sharing |
So, what happened with this ? I'm still dealing with Expected to decode Date but found FIRTimestamp instead. What do you guys suggest to solve this ? I have a Date object in my model |
** |
@alickbass seems like Google merged Codable support into master firebase/firebase-ios-sdk#3198 didn't check the implementation or test it out myself. Will do that and close this issue accordingly |
How did you end up doing this? |
How does it compare to this library? |
I'm running into this
Firestore is returning them in this format: My understanding is that I could use this library to decode from Timestamp directly to date like this:
Unfortunately it throws the error: Does anyone know how to solve this? I'm pulling my hair out trying to avoid writing a custom initializer or even a custom model for the one area of the app where this model gets loaded up from the Firestore. |
I'm trying to figure out how map to FIRTimestamp since it's not codable currently. Is there a way to transform the data returned from FIRTimestamp to Date instead or make FIRTimestamp codable so that it maps correctly?
The text was updated successfully, but these errors were encountered: