Fetch Firestore Documents
Tinder Firestore Swipe and Match
This lesson will cover the fun data fetching portion of our course. Now that we have our users stored inside of Firestore, we can make a very easy call to fetch this data and transform it into an actual User. Let's go ahead and complete this process by introducing a custom initializer for our User such that it can take in a document dictionary. We'll also have to be very careful of how properties are set up if they don't currently exist inside of Firestore.

Comments (10)
benpalmer661
4 years ago
the moment I have been waiting for thanks Brian!
ayon
4 years ago
Hi Brian tx for this amazing course. Do you have any plan in the future to extract the networking calls from the register View model to any networking layer later in this course series?
Brian Voong
4 years ago
ayon
4 years ago
I can understand the burnout man! There's a lot of stuff going in. You need a TA. :).
st4n
4 years ago
This could be really cool stuff.. Maybe it's material for some side mini-course.. I would really like to know the generic, enum based, protocol oriented approach to this network layer topic. Like in a production-ish code. There are some tuts online but mostly text and without explanation why this why that, thought process etc. Awesome course so far... can't wait for to see next episodes..
Eduardo Davila Nadal
4 years ago
That would be awesome Brian!! Thank you!!
dneckles
4 years ago
He does need a ta, i can sense a burnout hopefully one the people who've bought his course and learned from him, can help out, if Brian is open to that.
benpalmer661
4 years ago
Hi Brian behind all my cards is a square view and i don't what it is to set layer.cornerRaidius = 10 like the cards are, so there is a clipping of the corners of what i think cardsDeckView , / i don't know where to add the layer.cornerRadius = 10
Brian Voong
4 years ago
st4n
4 years ago
I had the same "problem" a few episodes back. I don't remember now where it was, but you have to make sure to set the cornerRadius + clipsToBounds somewhere in the code related to this view (maybe in CardView -> setupImageView func). Or somewhere else.. I honestly can't recall now. Long story short - I fixed it rather easily - you can too :) good luck..
st4n
4 years ago
comment in wrong place - sry (;
benpalmer661
4 years ago
i think i just figured it out , its the shading
benpalmer661
4 years ago
nope still haven't figured it out?
flashtrend
4 years ago
When tapping on a card, it the image goes away and the card becomes transparent. Is this an issue others are having at this point or did I make a mistake somewhere ?
Govind K Kara
4 years ago
Hi flash this is because for some users the imageUrl is nil.So the card appears to be transparent for those users.Go to your firestore and delete those users with no imageUrl1 key and the issue will be resolved!
mustii
4 years ago
Hey, I ran into the same problem and I believe brain will fix it later on, however the solution is to change the CardViewModel -> imageIndexObserver to return not an image but the url and let the CardView handle the rest for you since you will be using the SDWebImage
Nathan Hsiao
4 years ago
hi brian Not sure if its my internet slow but somehow i saw flashes of other image or only gradient layer when application started and i am sure i used sdwebimage correctly
Brian Voong
4 years ago
Cinquain
4 years ago
Anyone get this error? -> Failed to get FirebaseApp instance. Please call FirebaseApp.configure() before using Firestore'
Brian Voong
4 years ago
Cinquain
4 years ago
I've already done that of course. It seems that its a problem encountered by other developers as well: https://stackoverflow.com/questions/38168616/got-must-call-firapp-configure-before-using-firdatabase-error-even-though-i-a/38168909
Cinquain
4 years ago
I found the solution, my window creation codes: (window = UIWindow(frame: UIScreen.main.bounds), etc) were made before the firebase configure connection. I simply swapped their placement (putting the firebase code before) and the app didn't crash.
Dongjun Kim
4 years ago
Hi Brian! let professionString = profession != nil ? profession! : "Not available" in this code, when profession doesn't have initial value it shows nothing... ageString works well but I can't understand why it does
Dongjun Kim
4 years ago
I just fix it ... it was because the code in init function... sorry bro!
rehannali
4 years ago
Hi Dongjun! If this profession is optional why don't you use like this? let professionString = profession ?? "Not Available". I believe it is simple.
Zach Wilcox
4 years ago
Hello Brian, I have been trying to work with Firebase database throughout this course because in an project that I am working on it would be very very difficult to use firestore. On fileprivate func fetchUsersFromDatabase() { Database.database().reference().child("JobPost").observeSingleEvent(of: .value, with: {(Snapshot) in if let eachDict = Snapshot.value as? NSDictionary{ for each in eachDict{ let user = User(dictionary: eachDict as! [String : AnyObject]) // self.cardViewModels.append(key.toCardViewModel()) print(each.key ) print(each.value ) print((each.value as! NSDictionary)["title"] ?? "No data") } self.setupDummyCards() } }, withCancel: {(Err) in }) } I am having issues calling append. Is there a simple database work around?
HELP & SUPPORT