Cycling Through User Photos
Tinder Firestore Swipe and Match
For each card, one feature that is very useful is the ability to page between user photos on tap. The first bit of code we'll have to modify is our CardViewModel to allow it hold more than one single image. We'll introduce an imageNames property and also turn model into a class instead as it'll be easier to work with later on. By the end of the lesson, we'll have the ability to cycle through many photos that belong to a user.

Comments (9)
Cinquain
4 years ago
This video was fire!
Robin Wahlgren
4 years ago
thanks Brian for awesome videos and lessons. you are the only one I can watch on youtube to learn coding.
dclawson
4 years ago
Dumb question: what is the shortcut to add/remove the brackets on the imageNames variable?
dclawson
4 years ago
Never mind. Simple: Just highlight the text and press left bracket. Also works for braces and parentheses. Have to use the left variety, right doesn't seem to work.
Cinquain
4 years ago
Fire!
rehannali
4 years ago
Hi Brain! Thanks for this awesome course. My question is about your tapGesture location condition. You write is as tapLocation.x > frame.width / 2 ? true : false. What if you can write only tapLocaltion.x > frame.width / 2 because it gives you same result.
Omran_K
3 years ago
This would only give you forward movement whereas the ternary conditional operator gives you one of 2 values based on the condition which you then use to either move forward to the next photo or backwards to the previous one.
rehannali
3 years ago
Compiler gives you same result. If condition don't meet it gives you false else true. You don't need to write explicitly true and false. It's straight forward.
Omran_K
3 years ago
Oh yeah you are right but I guess that shows that his way is better for readability. It's a bit more clear what's happening and there's not more lines of code so why not make it easier for yourself in the future.
Brian Voong
3 years ago
arturfil@hotmail.com
4 years ago
Hi Brian, I'm having trouble with the project, I downloaded the project to check it with yours but for some reason I get an error after the build was successful. The error says "Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)" Here is my github repo in case you want to check (error appears in the CardView.swift file > in "let imageView = UIImageView....") : https://github.com/arturfil/swift-tinder Thanks in advance, Arturo Filio Villa
Julia Pak
4 years ago
Brian, I'm enjoying these videos. You should do a mock Uber app.
David Guarino
3 years ago
Agree 100%......I did a tutorial course on Udemy last year just starting out and everything seemed so confusing with errors and and no flow at all. There's no doubt in my mind that if Brian did a course like that it would not only be far beyond exceptions BUT we would also GET IT!
joker45
3 years ago
Code suggestion / Code reflector for func handleTap. I think it's overkill to foreach arrangedSubvies.backgroundcolor and set all to barDeselectedColor. I guess it's just enough to place barsStackView.arrangedSubviews[imageIndex].backgroundColor = barDeselctedColor before "if shouldAdvanceNextPhoto" because at this time you have not changed the index, that is selected. Maybe safe some computing :)) Here full code: @objc fileprivate func handleTap(gesture: UITapGestureRecognizer) { let tapLocation = gesture.location(in: nil) let shouldAdvanceNextPhoto = tapLocation.x > frame.width / 2 ? true : false barsStackView.arrangedSubviews[imageIndex].backgroundColor = barDeselctedColor if shouldAdvanceNextPhoto { imageIndex = min(imageIndex + 1, cardViewModel.imageNames.count - 1) } else { imageIndex = max(0, imageIndex - 1) } let imageName = cardViewModel.imageNames[imageIndex] imageView.image = UIImage(named: imageName) barsStackView.arrangedSubviews[imageIndex].backgroundColor = .white }
joker45
3 years ago
funny, posted this on 22 Jan 2020 and it shows 4 months ago, Brian i guess you should run time-update on your webserver :))
joker45
3 years ago
OMG now the time is correct?? Trust me i'm not crazy :D
Brian Voong
3 years ago
Lmaret
2 years ago
Hello Brian thank you for all your great videos. I am new to the language of swift. I wanted to know if you've some experience with KolodaView?
HELP & SUPPORT