Image Picker Bindable Image
Tinder Firestore Swipe and Match
I'd like to spend this lesson on some more elaboration of the MVVM architecture model. Ideally, we'll want to set up our RegistrationViewModel object to reflect what we have in our RegistrationController page. This way we can keep track of all the appropriate properties inside a single class. To make our code much easier to write, we'll introduce the construct of a Bindable that allows for binding from external classes. Lots to learn and you'll see these patterns a lot in Reactive style programming.

Comments (17)
flashtrend
4 years ago
Hi, after adding a picture, the screen doesn't adjust when the keyboard opens and closes, how do I fix that?
Brian Voong
4 years ago
flashtrend
4 years ago
In the handleSelectPhoto() function ?
Brian Voong
4 years ago
flashtrend
4 years ago
It seems to be an issue related to removing of the observer in the viewWillDisappear, when commented out it solves the issue. Im assuming that when the image picker opens it counts as a viewwilldissapear ?
Brian Voong
4 years ago
PreachOnBerto
4 years ago
Thank you for bringing up Bindable and introducing reactive programming in this course. I've been looking for options to learn about reactive programming and using libraries like RxSwift. Any good sources you've used to learn RxSwift and how to apply it?
Daryl Wong
4 years ago
The bindable generic class just in case you would only want to cut and paste: class Bindable<T> { var value: T? { didSet { observer?(value) } } var observer: ((T?) -> ())? func bind(observer: @escaping (T?) -> ()) { self.observer = observer } }
Alvathor
4 years ago
thx
Paweł Liczmański
4 years ago
thx m8
ravikanth.marri@gmail.com
4 years ago
Hi Brian, Thank you very much , you made it very easy to understand. Your show and tell technique is amazing.
Ashim Dahal
4 years ago
Hi Brian, can you let me know why Bindable is class and not as struct? Can you please reason based on value type and refrence type? and why bindable can't be struct type?
Brian Voong
4 years ago
Ashim Dahal
4 years ago
wow .. that was very quick response... thank you very much
stonypig1
4 years ago
hello Brian, would you teach us how to select multi photos while using the unpickercontroller, which is practical these days, but I can't find any tutorial that show us how to do it. thanks
Gino
4 years ago
Hey! Is there a reason why we don't use RxSwift since we use MVVM with reactive style programming for the whole project anyway?
Brian Voong
4 years ago
李承諴
4 years ago
hi Brian why we use the "closure" will cause "retain cycle"?
Dongjun Kim
4 years ago
Hi Brian! After I select a photo from imagePickerView, handlekeyboardShow() doesn't work. Why is it happening?
Brian Voong
4 years ago
Dongjun Kim
4 years ago
Thanks bro, The reason was removeObserver in viewWillDisappear so,I moved setupNotificationObserver() to viewWillAppear() It works perfectly!
Michalis
4 years ago
Hi Everyone! In Swift 5 and Xcode 10.2 I had to install lastes versions of Firebase pods to make it run. In the result StorageReference.downloadURLWithCompletion() function is marked as deprecated. Although it still works fine I changed that part to: let storageRef = Storage.storage().reference().child("images").child(filename) which looks even cleaner. I hope this helps. And big thanks to Brian for another great tutorial. I really appreciate you teach clean and modern code one can use professionally. Not this storyboard+hugeviewcontroller stuff you get everywhere on the net. Thanks! Michal
Thanh Minh
4 years ago
storageReference.downloadURL(completion: { (imageLink, err) in if let err = err { print(err.localizedDescription) return } ... })
rehannali
4 years ago
Hi Brain! There is a good concept of Bindable and I kinda like it. There is a problem or actually not a problem but a little bit headache to break retain cycle and we need to write [unowned self] every time. What if we manage it inside bindable somehow. I got inspired by a medium post and try to write it closure with delegate so to speak. Here is a link to the code snippet. Could you please give feedback and thoughts regarding the above question and this code snippet? https://pastebin.com/QWkhChim
Brian Voong
4 years ago
romulusc
4 years ago
Hi Brian. When running on external Xs, Ui elements jump if I get the autocomplete email address from top of keyboard in emailTextField. Same UI jump if I first try to fill passwordTextField. No UI jump in the nameTextField though…. Compiler displays API error: <_UIKBCompatInputView: 0x106d02f40; frame = (0 0; 414 243); layer = <CALayer: 0x28047e880>> returned 0 width, assuming UIViewNoIntrinsicMetric ....for email field and similar for password field. Can’t seem to find a solution after research. Any idea guys?
Brian Voong
4 years ago
romulusc
4 years ago
Hi, thanks Brian. Tried scrollView now and keyboard only goes up tu the active field, covering the ones below...mmm, it was nicer with the stack view with keyboard stuck below the buton, i've been trying to marry the 2 methods together somehow, the stackview on top of the scrollview or just the scrollview in the bottom part below the stackview, to no avail. In the end i'll use maybe something like your facebook messanger signup page type. Just wondering if it was possible somehow to get the same keyboard behavior that we get from the stackview method in the scrollview method, so basically to get the keyboard come up and push the UIelemnts up a bit if needed, rather then covering them. I'm no expert or advanced coder, maybe not intermediate even, but i enjoy finding solutiong, don't like to give up...unless maybe the solution i'm looking for its not possible.
Cinquain
4 years ago
That video was fire!
serxhio
4 years ago
truly was!
fkeebie
4 years ago
New layout and feel of your website letsbuildthatapp.com are cool! Readbility has also remarkably improved.
Julia Pak
4 years ago
How did you get the photos into simulator?
lbta
4 years ago
mrchanlee
3 years ago
Hi Brian, I have a question regarding bindable. What purpose does the func bind serve? In the RegistrationViewModel before bindable we were able to get away without such a function. It seems like it another step. Does it serve a purpose I'm unaware of?
Brian Voong
3 years ago
aymather
3 years ago
Setting up the bindable class, is technically another step, but the purpose is so that in your ViewModel classes, you no longer always have to set the type of the observer which is what he means by "crazy syntax". For example, you no longer have to type this -- let observer: (() -> ())? Because the bindable is setting that for you by using the `bind` initializer setting your closure that you pass in to this -- -- Inside "bind" function the type is already defined, so you just set your closure to it self.observer = observer
Ally Makongo
3 years ago
After registration, how can I get a user token so that I can use it to authenticate the user on my endpoints for node JS using Firebase Admin SDK?
HELP & SUPPORT