Apologies
You must be signed in to watch this lesson.
One final feature we'll have to implement in this video is the ability to persist our selected user photos in our Settings page. We'll go ahead and first upload our select photo into storage and manage the image urls on our User object. Whenever we hit the save button, we'll simply save these two properties as imageUrl2 and imageUrl3 for our user. Enjoy.

Comments (16)
st4n
5 years ago
yo, it's me again ;) I wonder..in the real world app.. what would be responsible for cleaning old photos (assuming 3 photos per user)? Some bots / processes on the server automatically? Or app/client itself?
Brian Voong
5 years ago
Prabhdeep Singh Randhawa
5 years ago
hi Brian, at the moment we r just using dummy emails for login or registering.How will we verify if the email is real or not.
Brian Voong
5 years ago
johnrm9
5 years ago
Hi Brian, Here's something I discovered .. using the higher-order function compactMap (compacts out nil items) for CardViewModel - func toCardViewModel() -> CardViewModel { ... let imageUrls: [String] = [imageUrl1, imageUrl2, imageUrl3].compactMap { $0 } return CardViewModel(imageNames: imageUrls, attributedString: attributedText) }
Christophe Bugnon
5 years ago
You can just use a map, you'll never get optional at the end because your initialization is no optional. It'll be little more slowly at the compilation if you put compactMap everywhere and you didn't need. Otherwise, this is nice. :)
Christophe Bugnon
5 years ago
Ok I understand what you did, this is good to use compactMap. Good job guy :)
Ivica Petrsoric
5 years ago
hey there, could you go a bit in deep with what you mean at 21:12, a fix for the flashing?
Ivica Petrsoric
5 years ago
nvm, got it my self :) PS1: it would be nice to have delete comment :D PS2: something is wrong with the percentage of video completion (can't hit 100%, always around 97-99%)
Cinquain
5 years ago
That video was fire!
richardbranson
4 years ago
some flashing occurs is a big bug because it's showing the backside of a photo for a little bit milliseconds please solve this. when I run the app last image showing for milliseconds in the first position and then original image is showing.
Brian Voong
4 years ago
richardbranson
4 years ago
ok thanks brian actually I am in the episode 28
pdefilippi
4 years ago
Hey Bryan, I am getting a crash on the line let imageUrl = imageNames[imageIndex] in the CardViewModel / Fatal Error: Index out of range. I also am not getting the barView to show when I have a single image only in my project. I was not getting an issue before this video and have compared my code to your project. I don't see anything different. I understand the error but am not sure how to trouble shoot it. fileprivate var imageIndex = 0 { didSet { let imageUrl = imageNames[imageIndex] //let image = UIImage(named: imageName) immageIndexObserver?(imageIndex, imageUrl) } } // Reactive Programming var immageIndexObserver: ((Int, String?) -> ())? func advanceToNextPhoto() { imageIndex = min(imageIndex + 1, imageNames.count - 1) } func goToPreviousImage() { imageIndex = max(0, imageIndex - 1) }
Dino32
4 years ago
Hi! Do find an issue ?
pdefilippi
4 years ago
Not sure what you are asking Dino. Can you give me some more context?
Dino32
4 years ago
Sorry, I mean this issue Hey Bryan, I am getting a crash on the line let imageUrl = imageNames[imageIndex] in the CardViewModel / Fatal Error: Index out of range. I also am not getting the barView to show when I have a single image only in my project. I was not getting an issue before this video and have compared my code to your project. I don't see anything different. I understand the error but am not sure how to trouble shoot it. fileprivate var imageIndex = 0 { didSet { let imageUrl = imageNames[imageIndex] //let image = UIImage(named: imageName) immageIndexObserver?(imageIndex, imageUrl) } } // Reactive Programming var immageIndexObserver: ((Int, String?) -> ())? func advanceToNextPhoto() { imageIndex = min(imageIndex + 1, imageNames.count - 1) } func goToPreviousImage() { imageIndex = max(0, imageIndex - 1) }
Dino32
4 years ago
Sorry for my privious confusing comment. The issue with error "index out of range" is occurs because you have one registered user witch hasn't url image. After you will delete that user the problem is go away.
pdefilippi
4 years ago
Oh, Awesome. I didn't think about it from this perspective. I was thinking I made a code change that wasn't working. Thanks for the feedback.
pushkar
4 years ago
In my one of the project, I have used UIViews for horizontal list.. Then understood what it's like when you don't use recycler component! (Loads of performance issues) Which is why I need to rewrite entire feature. :( But any way, there won't be any performance overhead in our case since we are removing entire UIView from superview on swipe and we have a pagination in place. But loading 200 cards in a batch will still be expensive? What do you think? I would really appreciate if you kinda add another video which uses CollectionViewCell instead of UIView for cards..
Brian Voong
4 years ago
pdefilippi
4 years ago
Hey Bryan, Any advice on the issue I posted a few days ago? Do you need more info to assist?
pdefilippi
4 years ago
nvm Bryan, Figured it out. Set a bunch of breakpoints and realized I was never getting a user object returned. Made the necessary adjustments and am all good.
Zach Wilcox
4 years ago
why does firebase only show "imageUrl3 = "";"?
Zach Wilcox
4 years ago
sorry couldn't​ delete this post but my images are stored in storage, but not in the database. I've followed along perfectly, and I just can't seem to figure out why that is.
mashype
4 years ago
Looks like you have some syntax problem with too many "". Is it just image 3 of all of them?
Cinquain
4 years ago
Fire!
ericathanas
4 years ago
Has anyone implemented the change to upload the photos upon pressing save (14:10)? I am trying to do it but I think it requires a closure as it doesn't otherwise wait for the entire uploadPhotos function to finish before continuing handleSave. I can't seem to figure out how to do it.
Eugeneberezin
4 years ago
Hey Brian, For some reason when I go back to the Settings controller the data that I have saved is not there. After I upload the images I get this for the user USER>>>> Optional(TinderFireStoreEB.User(name: Optional("Qu"), age: Optional(25), profession: Optional("Dev"), imageUrl1: Optional("https://firebasestorage.googleapis.com/v0/b/matchfirestoreeb.appspot.com/o/images%2F1E17BD03-4A69-4415-9D8A-7CBA7FD8BA1A?alt=media&token=e94974f3-a6bd-47aa-ada9-7e682c23d982"), imageUrl2: Optional("https://firebasestorage.googleapis.com/v0/b/matchfirestoreeb.appspot.com/o/images%2F2E8C6F1E-31AC-45AD-B635-F4032C6736FE?alt=media&token=0fcda562-5659-423b-9e6c-1b9fcff1a62a"), imageUrl3: Optional("https://firebasestorage.googleapis.com/v0/b/matchfirestoreeb.appspot.com/o/images%2F615D50A5-80D2-49D6-BFE3-9586D52DC36C?alt=media&token=d8bf5e84-21b0-4b03-8943-d03141100789"), uid: Optional("OvEk2miWTpY3QwVmg8mspPAEMfH2"))) . It is after I click save button. If I click cancel and go back to @objc fileprivate func handleCancel() { dismiss(animated: true) } My data is not there and I get imageUrl2: nil, imageUrl3: nil . Couldn't figure out why it is happening..... Any help would be appreciated.
Eugeneberezin
4 years ago
And I verified that my data saved in the firestore.... I see those URLs
Eugeneberezin
4 years ago
And as I typed my question out.... I found the bug.... In my User modal, I forgot to put self.imageUrl1 = dictionary["imageUrl1"] as? String self.imageUrl2 = dictionary["imageUrl2"] as? String self.imageUrl3 = dictionary["imageUrl3"] as? String It fixed the issue. I hope it will help anyone if someone comes up with a similar issue.
Thanh Minh
3 years ago
Same with textfield, we can also set button.tag for more clean code.
Brian Voong
3 years ago
Thanh Minh
3 years ago
Yes, Thank you Brian. I always follow you. Especially of all your courses.
wy34
2 years ago
I think currently the way we are storing images to Storage, its able to be duplicated. We are saving it under a uuid, so if someone selects the same image again and save, they are technically uploading the same image but just under a different name. Is there any way to avoid that?
HELP & SUPPORT