No video

Fetching Firebase Firestore data with Codable in Swift | Firebase Bootcamp #10

  Рет қаралды 11,344

Swiftful Thinking

Swiftful Thinking

Күн бұрын

In this tutorial, you'll learn how to use the Codable protocol in Swift to fetch data from Firebase Firestore. With Codable, you can easily map your Firestore data to custom model objects, making it easier to work with your data in your iOS application. Follow along as we walk through the steps to set up your Firestore data model and decode your Firestore documents using Codable. By the end of this video, you'll have a solid understanding of how to use Codable to fetch and work with data from Firestore in your Swift application.
🤙 WELCOME BACK 🤙
WEBSITE: www.swiftful-t...
DISCORD: / discord
GITHUB: github.com/Swi...
SAY THANKS: www.buymeacoff...
00:00 Firestore Codable
01:57 Intro
03:40 Managing database references
05:56 Codable
10:52 Encoder for snake_case
12:40 Decoder for snake_case
15:56 Customizing DBUser init
17:40 Adding isPremium
20:06 Updating a struct
27:18 Mutating a struct
30:20 setData vs updateData
34:41 Custom coding strategies
38:45 Custom Coding Keys
42:03 Conclusion

Пікірлер: 52
@kdtechniquesofficial6153
@kdtechniquesofficial6153 Жыл бұрын
I love the way you took the time to teach us how to scale our code in an efficient way by doing it the hard way first and then changing the code in an efficient and scalable manner. Thank you, Nick.
@iLoveAppl3947
@iLoveAppl3947 Ай бұрын
for someone coding along this can be a pain in the azz. He can do it correctly from the beginning that would save so much time and confusion
@TaylorOgburn
@TaylorOgburn 10 ай бұрын
I have never watched a KZbin video and actually learned something from them. The content is always over my head or so basic that I'm yawning. Nick, you are CRUSHING these, and I can honestly say my time in college is nowhere near as valuable as the knowledge I'm getting from your videos. RESPECT!
@sattorjabborov2728
@sattorjabborov2728 Жыл бұрын
You could do it using just one way to keep the video short, BUT I REALLY APPRECIATE THE WAY YOU SHOW US ALL POSSIBLE WAYS TO DO ONE THING. YOUR VIDEOS ARE 🔥
@andresraigoza2082
@andresraigoza2082 Жыл бұрын
Thank you so much Nick! Just a note at 21:58, if you extract the init(auth: AuthDataResultModel) { … } to an extension of the same struct you will get your memberwise initializer back, meaning that you won’t need to write this init() at all.
@MaksimLA
@MaksimLA 10 ай бұрын
I love the way you show easy way in one video and then advanced in next! Gives me much better context and understanding! Thank you so much for your work
@danielwatson6529
@danielwatson6529 7 ай бұрын
ive been working with swiftui/firebase for a while and doing incredibly well (I had thought) this is awesome stuff. I literally feel like you have made me a professional the layers of polish you have given me is insane. im so so grateful, reckon ill be leaving my day job soon because of all the hard work I have put in, combined with the absolute mirical of the modern world where I can latch on to an incredible mentor as someone like your self. you are a golden egg THANK YOU SARNO!!!
@vojtechkalivoda8455
@vojtechkalivoda8455 Жыл бұрын
ERROR FIX: encoder (11:20) I have an error saying that: Firestore.Encoder has no member keyEncodingStrategy ... 🙁 SOLUTION: It is just that u have different firebase version!!! Go to your project in Xcode(not target, but project!!) -> Package Dependencies -> double tap on Firebase -> select Exact version -> set it to his version which is 10.4.0 :) and you are ready to continue 😇
@killian8703
@killian8703 Жыл бұрын
this works. thank you
@ZL-Asica
@ZL-Asica Жыл бұрын
works!
@user-xd2fg4wp3l
@user-xd2fg4wp3l Жыл бұрын
Legend cheers
@lucyferyx
@lucyferyx 8 ай бұрын
I hope your pillow is always cold on both sides
@sraldous
@sraldous Жыл бұрын
Amazing, I'm loving this Firebase Firestore series, thank you so much for sharing your knowledge. I'm learning a lot!
@SwiftfulThinking
@SwiftfulThinking Жыл бұрын
That’s great to hear! 😁
@nikodemeroutis
@nikodemeroutis Жыл бұрын
Big big thanks !! But I don't know why when I try to make an encoder (11:20) I have an error saying that: Firestore.Encoder has no member keyEncodingStrategy ...
@iLoveAppl3947
@iLoveAppl3947 2 ай бұрын
lots of boilerplate code in this video... complicated as f and this makes me use CloudKit
@dereknoppinger9129
@dereknoppinger9129 Жыл бұрын
This series has been a godsend. Thanks a lot man.
@loudibird
@loudibird 10 ай бұрын
bro youre the best. your gonna live forever through our code
@melmandaragrows
@melmandaragrows Жыл бұрын
Wow, this was great. I’ll have rewatch so many times
@SwiftfulThinking
@SwiftfulThinking Жыл бұрын
You got this Mel 👍🚀
@user-fk7jl4ht1c
@user-fk7jl4ht1c 4 ай бұрын
Wow...... Thank you, Nick. 🙏 This was a great job ! )
@kdtechniquesofficial6153
@kdtechniquesofficial6153 Жыл бұрын
We are super excited too. Buckle up, and let's go. Boom Boom Boooooooom. 🚘
@SwiftfulThinking
@SwiftfulThinking Жыл бұрын
🏎️🏎️🏎️
@aliabraham1725
@aliabraham1725 Жыл бұрын
Fantastic Work! This is so helpful. I'm building and app with firebase & I will go back make changes to make my app more efficient. Thank you!
@SwiftfulThinking
@SwiftfulThinking Жыл бұрын
Thanks 😁😁
@user-mw2sq3cw1s
@user-mw2sq3cw1s 9 ай бұрын
Every time you make it so easy thanks!!
@pakaponwiwat2405
@pakaponwiwat2405 Жыл бұрын
Thank you very much, mr. Nick!
@omerfarukozturk9720
@omerfarukozturk9720 7 ай бұрын
Content 🔥
@ThinThedev
@ThinThedev Жыл бұрын
I tweaked the code a little and instead of using the encoder, I just used CodingKeys within the DBUser Struct. This essentially let's you specify a mapping between the your struct values and the Firestore values and reduces the need for using the firestore specific encoder/decoder.
@jonothen2212
@jonothen2212 9 ай бұрын
anyone tried to write .setData(from: ) and get this error: Cannot convert value of type 'myDatatype' to expected argument type '[String : Any]' when i typed .setData(from:) this func is grayed and get this: this method is defined in DocumentReference but my not be available in this context? thanks guys.
@mahoozi.97
@mahoozi.97 5 ай бұрын
great tutorial , I add displayName property in DBUser struct, when I signed with google I got displayName, but I didn't got displayName when I signed in with apple, also I facing same issue with photoUrl !
@SwiftfulThinking
@SwiftfulThinking 5 ай бұрын
Different SSO options provide different bits of data unfortunately. You can customize what data you’re requesting in the SSO sign in request, buts it’s still limited.
@juliansha2590
@juliansha2590 Жыл бұрын
Amazing stuff thank you :)
@SlidE933
@SlidE933 Жыл бұрын
12:40 I try to decode for snake case, but this the method doesn't work, even if I copy this code, if I use old method with dictionary, it works...
@lincolndickerson1293
@lincolndickerson1293 Жыл бұрын
Very thorough! Thank you. One thing that struck a sour note. You mentioned your preference to be ready to adapt to a bad key. Which at first glance seems great. Consider this, if you have to do that often then certainly be prepared. On the other hand creating the custom keys only if needed and its a very rare occurance which has been my experience saves many, many lines of code over many projects. Code that doesn’t exist doesn’t need to be tested. No typo’s on your end with keys if they are generated. One thing that I do find appealing is having one source of truth for the key itself. Do you know of a way to get the autogenerated key?
@SwiftfulThinking
@SwiftfulThinking Жыл бұрын
I don’t think there’s a way to get the auto-generated keys, probably because if you don’t declare the CodingKeys, they are open to change based on the decoder preference.
@zacmasters7744
@zacmasters7744 Жыл бұрын
Has Firebase deprecated setData(from: ) ? I can't seem to get it this version of setData working.
@lincolndickerson1293
@lincolndickerson1293 Жыл бұрын
I know that traditional REST and JSON use snake case for keys. But it is not really necessary to be functional. Why not just leave it with camel case and let the swift decoder handle the decoding without customizing the coding and decoding? I will work. I tried it to be sure.
@SwiftfulThinking
@SwiftfulThinking Жыл бұрын
As I showed in the video, it definitely works… but if you ever don’t follow the decoding rule exactly, you’ll have major problems. I think this is a pretty common situation in more prod apps I’ve worked with. Just offering my two cents.. do what’s best for your project!
@melmandaragrows
@melmandaragrows Жыл бұрын
When I try the to use private let encoder: Firestore.Encoder = { Let encoder = Firestore.Encoder() Encoder.keyencodingstrategy = .convert to snake case Return encoder }() I get two errors 1. Value of type ‘Firestore.encoder’ has no member ‘keyencodingstrategy’ 2. Cannot infer contextual base in reference to member converttosnakecase
@rasheed1andrew
@rasheed1andrew Жыл бұрын
I'm facing the same problem and can't seem to figure it out
@melmandaragrows
@melmandaragrows Жыл бұрын
@@rasheed1andrew I reached out to google, I sent them a GitHub gist of the code for authmanager and usermanager, I think it might be a weird bug. They are working with me to try to figure it out. Will update whenever I get an answer.
@rasheed1andrew
@rasheed1andrew Жыл бұрын
@@melmandaragrows I figured it out. Check the version of Firebase you are currently using. Delete the one you currently have and when you download it again set the version to 10.0.0
@rasheed1andrew
@rasheed1andrew Жыл бұрын
@@melmandaragrows use the exact version Nick used in the video
@crawford6337
@crawford6337 11 ай бұрын
trying to follow along with this video and i'm running into an issue where firestore doesn't recognize encoder/decoder and is not allowing the profile info to show in the simulator. Chatgpt says swift doesn't use custom encoder/decoder and it has it's on default decoders. I'm stuck and lost and frustrated. Please help if you can.
@SwiftfulThinking
@SwiftfulThinking 11 ай бұрын
Join the discord and someone will help you out: discord.gg/vhKKyYTGDb
@iLoveAppl3947
@iLoveAppl3947 Ай бұрын
don't follow along this is terrible to do... this guy is wasting your time
@loudibird
@loudibird 10 ай бұрын
can I give you equity in the app I'm trying to make
@DaikiKaneda
@DaikiKaneda Жыл бұрын
😍
@user-ju9dy4yn2b
@user-ju9dy4yn2b Жыл бұрын
you write code difficult af , you only write as you want and I hate the way you write code
@vojtechkalivoda8455
@vojtechkalivoda8455 Жыл бұрын
Lets gooooo, love this video!!! 🔥🔥🧯
@SwiftfulThinking
@SwiftfulThinking Жыл бұрын
Let’s gooooo🚀🚀🚀🚀
Live updates  12/08/24
23:03
Pharma Job Alert
Рет қаралды 91
小丑把天使丢游泳池里#short #angel #clown
00:15
Super Beauty team
Рет қаралды 34 МЛН
EVOLUTION OF ICE CREAM 😱 #shorts
00:11
Savage Vlogs
Рет қаралды 14 МЛН
Swift API Calls for Beginners (Networking) - Async Await & JSON
25:35
Advanced offline caching techniques in Cloud Firestore
12:34
Firebase
Рет қаралды 17 М.
SwiftData Basics in 15 minutes
15:18
CodeWithChris
Рет қаралды 43 М.
Cloud Firestore Get Data (and other operations) with SwiftUI
41:31
CodeWithChris
Рет қаралды 42 М.