Apologies
You must be signed in to watch this lesson.
Save Settings Delegation
Tinder Firestore Swipe and Match
In this lesson, we'll go over how we can utilize the persisted settings data from Firestore to filter out the cards inside of the HomeController components of our application. The first thing we'll do is to make sure our Firestore query includes two fields of less than and greater than. Next we'll have to fetch our currently logged in user to see what these min/max values are. Finally, we'll apply some custom delegation to invoke our user fetching after our settings is saved inside of SettingsController.

Comments (13)
tonystarkli
5 years ago
great tutorial on delegate!
st4n
5 years ago
there is a small bug in your challenge solution code :) in HomeController, fetchCurrentUser function you have to move self.hud.dismiss() call out of the error block :) other way it keeps spinning :) unless there is an error ofc :)
Brian Voong
5 years ago
Sean Sneed
5 years ago
I had this experience as well but didn't know the cause. fixed it with your suggestion. thx ^_^
st4n
5 years ago
Hey again, could you provide with some fixes? :) 1. Pagination when sorted 2. Disable age sort / show users with N/A age 3. Omitting our current logged in user in fetched/displayed results 4. Save Bio. And (as i wrote a couple episodes back) multi-line bio display :)
Dennisvm82
5 years ago
Thanks for the very well explained delegation method :-)
Daryl Wong
5 years ago
Short and sweet in the delegation explanation. Just started working as an iOS developer for a week. I just went and check on the code in my assigned project and I realised that the previous developer did not implement any protocol and delegation methods. She was an experienced Objective C developer and and even with her experience in Objective C, she did not use any protocols when she moved into swift. I certainly hope to have a chance to implement some protocols in my current project.
Brian Voong
5 years ago
Cinquain
5 years ago
More Fire!
Yan Cervantes
5 years ago
Hi Brian i have a little question, i see in some projects, there some protocols have "class" word after the name of the protocol like this... protocol nameProtocol: class { func nameFunctionDelegate() } and when the instance is created, they call like this.... weak var delegate: nameProtocol? ( i dont know if is like for the retain cicle? maybe?)
Brian Voong
5 years ago
Yan Cervantes
5 years ago
Thanks for the answer! I think I will use that and avoid the retain cicles.
frankcrest
5 years ago
one question: why is settingsController.delegate = self in the handleSettings function of the home controller? Can this be in the viewDidLoad section?
Brian Voong
5 years ago
frankcrest
5 years ago
ohh, i get it, that is the only place where you can actually set a delegate to the settings controller because there's no other place in home controller to get access to that instance
frankcrest
5 years ago
I noticed a bug at this point, not sure if it is going to be fixed in later lectures. If you keep hitting refresh button, new cards will keep being appended to the array and the same cards will be added to the card stack.
NessGrey
4 years ago
I can't download the project
Brian Voong
4 years ago
大雄
4 years ago
Hi~Brian i have error, i don't kown how to fix. Error message: Object is destroying itself properly, no retain cycles or any other memory related issues. Memory being reclaimed properly
ndevereaux
4 years ago
Hey Brian, I'm wondering what you think of my solution to your challenge at the end of this video. I used a protocol with a default implementation of the function. protocol FetchCurrentUser { func fetchCurrentUser(completion: @escaping (User) -> ()) } extension FetchCurrentUser { func fetchCurrentUser(completion: @escaping (User) -> ()) { guard let uid = Auth.auth().currentUser?.uid else { return } Firestore.firestore().collection("users").document(uid).getDocument { (snapshot, error) in if let error = error { print(error) return } guard let dictionary = snapshot?.data() else { return } let user = User(dictionary: dictionary) completion(user) } } } Calling it in HomeController would look like this: fetchCurrentUser { user in self.user = user self.fetchUsersFromFirestore() } Calling it in SettingsController would look like this: fetchCurrentUser { user in self.user = user self.loadUserPhotos() self.tableView.reloadData() }
ndevereaux
4 years ago
I updated the completion handler to take an optional User? so I can pass nil if we fail to retrieve the user.
Brian Voong
4 years ago
Greg Reda
4 years ago
Hey Brian, I'm looking to refresh the stack while on the main screen without having a user logged in. Any ideas?
Ally Makongo
4 years ago
How can you refresh the stack without having the user logged in? we get user id and based on that, we do the filtering. Come on!
HELP & SUPPORT