Configure Bottom Controls
Tinder Firestore Swipe and Match
In this lesson, we'll take a look at implement the swipe behavior for our CardView objects whenever we hit the like button at the bottom of our application. The solution we implement will utilize something called a Linked List data structure. Setting this up isn't all that difficult, we simply need a "next" property and assign it inside of our fetch call.

Comments (3)
Dennisvm82
4 years ago
Clicking refresh whilst having visible cards in our cardViewModel currently keeps adding the same cards to the deck. Is the below solution a good way to fix this? @objc fileprivate func handleRefresh() { topCardView != nil ? nil : fetchUserCards() }
Bensalem Ilyes
4 years ago
add this ---> cardsDeckView.subviews.forEach({$0.removeFromSuperview()}) top your code in fetchUsersFromFirestore() fileprivate func fetchUsersFromFirestore() { let minAge = user?.minSeekingAge ?? SettingsController.defaultMinSeekingAge let maxAge = user?.maxSeekingAge ?? SettingsController.defaultMaxSeekingAge hud.textLabel.text = "Fetching Users" hud.show(in: view) cardsDeckView.subviews.forEach({$0.removeFromSuperview()}) let query = Firestore.firestore().collection("users").whereField("age", isGreaterThanOrEqualTo: minAge).whereField("age", isLessThanOrEqualTo: maxAge) , , , , , , }
Christophe Bugnon
4 years ago
I have to admit that I have trouble making the relationship for the nextCardView ... Could you give me a little example on a gist or something like that with a simpler example? Playground or something like that. Thank you in advance. :) Best regards.
Humberto De La Cruz
4 years ago
So imagine Jane, Rob, Marc and Tim come to the playground and make a line in that order. Each with with a picture of an orange, apple, banana, and strawberry, each fruit representing each of them. I have a photo copier. I go to the from of the line and make two copies of the same first fruit, orange, one for myself (I put it in my pocket, this is the only copy I will make to myself) and make another for Jane, I make also a copy of the next person's fruit, the apple and give both to Jane, so Jane has orange-apple. Go to the next person and make a copy of his fruit and the next person fruit, so Rob has an apple-banana , and Marc has banana-strawberry, etc. Then they all go run around and disperse in the playground. I take the picture of the orange out my pocket and call out for orange, Jane comes running. I say I don't like oranges, and crumble mine and hers oranges pictures, leaving only the apple. I call out apples, and marc comes running with his apple-banana pictures, I say I don't like apples, and crumble the one apple picture. leaving only bananas. I call out bananas and Jim comes running. I destroy the banana, leaving only the strawberry. So first time around the loop, making a copy of the first orange and keeping it to myself is: if self.topCardView == nil { self.topCardView = cardView } Making the photo copies and handing each person a copy of their fruit and next person card is what the code does in the loop via; previousCardView?.nextCardView = cardView previousCardView = cardView When the view controller shows me the topCard is me looking at the orange in my pocket. When I swipe left, is me calling out for the oranges person and destroying all the oranges. She showing the apples is "topCardView=TopCardView.nextCard", meaning the oranges (topCard...) person next fruit (..nextCard) Me calling out for apples is the view controller showing me the next . When I swipe left, is me destroying all the apple pictures and the Rob (topCard..) showing next person fruit (...nextCard): "topCardView=TopCardView.nextCard". etc. I think the most important thing is to realize that each time around the loop with previousCardView?.nextCardView = cardView previousCardView = cardView You are not continuously replacing previousCardView unique copy of it, but make a unique copy of it.
Christophe Bugnon
4 years ago
Wahouuu, thanks a lot for this explanation. I understood this story and it is easy to keep in mind. :)
David Guarino
4 years ago
Great analogy! This definitely helped my understanding on this lesson a lot better. Thank You
jke661s
4 years ago
Hi Brain, I'm just wondering why we call "self.topCardView?.removeFromSuperview()" in didRemoveCardView function in HomeController? That card view was removed in CardView in handleEnded function, and it works fine when I tried to comment the "self.topCardView?.removeFromSuperview()".
Ata Etgi
2 years ago
I have same question.
HELP & SUPPORT