Storage Image Upload Clean Code
Tinder Firestore Swipe and Match
With our user now logged in, we can now access Firebase Storage and start uploading photos that we want to register. Let me first show you how the putData method call is performed in code. Once everything completes successfully, we'll refactor all of our Firebase methods into our RegistrationViewModel file. Remember to always keep your controllers as clean as possible.

Comments (22)
Te-Jen Wu
4 years ago
Hi Brian, In my opinion, NotificationCenter.default.removeObserver(self) could be put in the deinitializer of the RegistrationViewController. Just like below described. deinit { NotificationCenter.default.removeObserver(self) }
Brian Voong
4 years ago
Te-Jen Wu
4 years ago
Hi Brian, I've print a message in the deinit func. After registering and transferring the RegistrationController to HomeController, the message showed up.
Subhodip
4 years ago
Use it like -> override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) setupNotificationObserver() } Hope it works.
hugo asdadasdasd
4 years ago
HI Brian, I got error when try upload photo Error Domain=FIRStorageErrorDomain Code=-13000 "An unknown error occurred, please check the server response." UserInfo={object=images/734AE56F-6D0C-4208-81C7-5D8927866E66, ResponseBody={
hugo asdadasdasd
4 years ago
Hi Brian, Never mind! was just configuration in rules thanks
Ouen_theara
4 years ago
I meet problem like you how can you fixed
Dongjun Kim
4 years ago
Did you check your firebase storage on firebase website? You should start it on web first
Ouen_theara
4 years ago
Hi Brian, I go error when I upload image Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'URL scheme must be one of gs://, http://, or https:// '
Ouen_theara
4 years ago
I solve it now it my mistake
Ouen_theara
4 years ago
Hi Brian , I meet error like that please help me Domain=FIRStorageErrorDomain Code=-13010 "Object images/827A4398-40D3-4F54-B764-5D4FEE9725D5 does not exist." UserInfo={object=images/827A4398-40D3-4F54-B764-5D4FEE9725D5, ResponseBody={
Tube
4 years ago
If you download an uploaded image, it will come back as a .dms file. To avoid this, set the metadata like this: let metaData = StorageMetadata() metaData.contentType = “image/jpeg" ref.putData(imageData, metadata: metaData, completion:
Paweł Liczmański
4 years ago
thx m8
Tube
4 years ago
What is the point of setting up a bindable observer, and then calling it directly (registerVM.registerUser)?
sraffe
4 years ago
Register user is a function of the RegistrationViewModel and is not a bindable. You call it so that it can perform the registration process, which is unnecessary in the RegistrationController. The bindable element (registerVM.bindableIsRegistering) will let you update your UI based on if the bindableIsRegistering is true or false.
Tokyojogo
4 years ago
Hi Brian, I've been going over my project here and comparing it to your project file and I am having this weird problem with the registration. It keeps saying "The email address is badly formatted" even though i typed in valid email. Any idea on why this is happening? Its driving me bonkers! I was able to successfully create an account prior to this lesson but somehow after doing this, I keep getting this error and I can't figure out why.
Tokyojogo
4 years ago
Nevermind. I got it working again...
Ashim Dahal
4 years ago
Hi brian, my code has autolayout constraint issue due to view resizing in landscape and portrait mode when view transition for registration view controller. It displays view component correctly but I get this autolayout constraint warning... I tried to debug with debug logging but couldn't exactly get the frame where It was causing issue... could you please help with this?
Brian Voong
4 years ago
jyoti
4 years ago
Hi Brian, I am getting following error while downloading the image url, could you please help me on this. Object images/9B063D2A-B75D-447F-A1BA-0493EA33BD44 does not exist.
vladislav14141
3 years ago
Try to create Database on the site. It helped me.
pushkar
4 years ago
I just can't download the Project. It's getting stuck at very last moment!
pushkar
4 years ago
Download completed after 20 mins of wait. Not sure what was the problem. I believe I was on stable connection.
Brian Voong
4 years ago
pushkar
4 years ago
Cool. Cheers!
benjamin696969
4 years ago
Part6 to 9 was good MVVM, now every View components are in controller like MVC no ?
staikratoke
4 years ago
Hello, it's saying ref is a unresolved identifier
staikratoke
4 years ago
Just solved my own stupid question...
staikratoke
4 years ago
I keep getting a unknown error occurred please check server response. When hitting register to upload image to fire-store section of the video.
Brian Voong
4 years ago
staikratoke
4 years ago
Anyone there?
Brian Voong
4 years ago
staikratoke
4 years ago
Hey Brian, Any ideas on why this is happening? It's successfully creating the user in fireBase.
staikratoke
4 years ago
Well, I also figured out this one as well, I had to go into Storage on the firebase console and enable a default storage.
Brian Voong
4 years ago
Thanh Minh
4 years ago
I learned a lots from Brian about refactor code. Great thanks!
druvinskiy
4 years ago
Hey Brian, I keep getting an error that says "An unknown error occurred, please check the server response," and I can't seem to figure out what I'm doing wrong. I'd appreciate any guidance.
Cinquain
4 years ago
Brian was lit in that video
Brian Voong
4 years ago
Cinquain
4 years ago
Of course ;) I was reading Mastering MVVM and Mastering Core Data by Bart Jacobs so I was out for some time studying these two books. Now that I'm done I'm back on LBTA with an even sharper understanding. Do you know Bart Jacobs by any chance? He has great content, he's the only one worth comparing to you so far. Also, do you have any book suggestions for learning good utility patterns in app development?
Kārlis Bērziņš
4 years ago
Please not that if someone is receiving error: Object images/... does not exist then please go to firebase console and enable the storage. You need to select the server on which the images are stored. At least for me that was the case for brand new project
David Guarino
3 years ago
@ 19:31 as I'm going over the course lessons while looking at my app code from another project.....was saying "Come on!... He's right"
devatom
3 years ago
Hi ~ I received error code after upload image file but image was save. error code is Domain=FIRStorageErrorDomain Code=-13010 "Object images/229BFA0B-7E17-4EAD-89CD-441661E2B316 does not exist." ResponseBody={ "error": { "code": 404, "message": "Not Found. Could not get object", "status": "GET_OBJECT" } https?? Sorry, I am not good at English.
Brian Voong
3 years ago
matieuxren
3 years ago
Go to Console in Firebase, then go to "Storage" and "Get started" so you can select a server. Once done this error will disappear.
Omran_K
3 years ago
In iOS 13 since segues are automatically modal, when you present the imagePickerController, viewWillDisappear is not called so the keyboard will not stop working but another bug can happen where if the keyboard is shown when the imagePicker is presented that messes up the UI constraints. I called handleTapDismiss() inside handleSelectPhoto() to avoid this from happening.
Omran_K
3 years ago
This weird message output shows when I switch typing from the password textfield to one of the other textfields: [Snapshotting] Snapshotting a view (0x11c510ff0, _UIReplicantView) that has not been rendered at least once requires afterScreenUpdates:YES. This only happens in dark mode. I am testing on a physical device. iPhone 8+. When I switch to light mode this message doesn't output. I am trying to understand what causes this message and what it means. Is it just a bug? When I test the same scenario on Simulator, a different error shows: API error: <_UIKBCompatInputView: 0x7f98bf7274c0; frame = (0 0; 414 243); layer = <CALayer: 0x600001d399a0>> returned 0 width, assuming UIViewNoIntrinsicMetric Tried researching this but couldn't find the answer to these outputs.
HELP & SUPPORT