Are your problems fixed now? If they are still happening and you have tried the RxSwift/RxCocoa updates recommended, let us know what the error output is.
One of the more solid guides Iâve seen when it comes to explaining Rx, but needlessly complex iOS code bogs it down. I found myself saying âwait⌠what the hell does that do?â quite a few times to things that had nothing to do with Rx. A tableView displaying [String] segueing to a page that checks whether the String contains a valid phone number would have been more effective learning example than one with 1500 lines of code that add nothing to the example.
Hi I liked your tutorial , but can you explain (add to tutorial) how to work with observable if for example in card view controller with chocolates you want to change amount of some chocolates (remove,add more) and go back to previously view controller.
Thanks.
Hi Nathan - I actually purposely tried to isolate the code that validated the credit card information and expiration date (which I believe is what you mean rather than phone number, since thatâs not actually included in the billing info here) in another file.
Since it wasnât super-relevant to the actual implementation of Rx, which is what this tutorial was concentrating on, the idea was to make it simpler for the developer to focus on the result of those operations rather than what those operations themselves were doing by abstracting them out.
Obviously that wonât always be the case for everyone (clearly it wasnât for you), since everyone reads code differently, but this was the reason I took the approach that I did, for what itâs worth.
Hi Basconje - So if I understand your question correctly, the question is what happens if you change the number of chocolates in the cart when adding the the credit card. The tutorial isnât really set up to do this, but you can see the effect if, from the CartViewController, you remove all the chocolates by hitting the big red Reset button.
In the non-reactive version of the tutorial, the count of chocolates in the cart is re-calculated on viewWillAppear(_:) to display the updated value. But once the app is using Observables, that call is removed. Youâll notice the count is still re-calculated, and thatâs because code you added in setupCartObserver() is still watching the number of items in the cart. When that number changes, onNext is called, and the number updates automatically.
Hi my question how to work with singletone from different view controllers , if we have some view controllers that display data from singletone , how to subscribe to observer then for example 2 or more view controllers have elements subscribed to some data . In your tutorial on first view controller your subscribed to singletone , but if in second view controller will be element that can change it , or in third view controller , so that happen as ? how to make CartViewcontroller change data on 2 or more view controllers then his data changed ?
Sorry for my english.
PS. I know how to work in general with singletone , question how to work with RXSwift with observable.
PS. why let chocolates: Variable<[Chocolate]> = Variable([]) here your used Variable
let europeanChocolates = Observable.just(Chocolate.ofEurope)
both array , so why one time its Variable second time is Observable , that difference ?
Great tutorial! Iâve been waiting for a RxSwift tutorial on RW. Hopefully you guys will write a book on RxSwift. There are lots of tutorials out there for RxSwift but only a handful of them are easy to follow and comprehensive like this one.
Hey Basconje, let me take your PSâs first since those are a little clearer.
In the ChocolatesOfTheWorldViewController, I used Observable.just because I know that Chocolate.ofEurope is not actually going to change its content - Iâm mostly using RxSwift to set up the table view. This is why I added the note about just being a possible sign that using Rx is overkill.
In the cart, I set up chocolates as a Variable because I knew that value would change as the user added and removed chocolates to and from the cart.
I think, if I understand your main question correctly, youâre asking if itâs possible to add multiple view controllers as Observers of the cart. Yes! You can add as many Observers as you want to any Observable.
Itâs a little bit hard to picture in the current example, but imagine the same application set up for use on an iPad, with the ChocolatesOfTheWorldViewController as the master view controller and the CartViewController as the detail view controller. If you add them both as Observers to the chocolates array on the cart, each one will receive updates whenever that value changes. Theyâre both listening for changes to the same value, even though the actions they will take when that value actually changes are different.
Thanks for the killer tutorial! However, you called a closure parameter âtrailingâ when itâs not actually trailing. Not a big deal, of course, but it could confuse some folks just learning Swift.
Thank you very much for the tutorial. It is a bit hard to know what is really happening in background if you are not fit with generics (like me), but it is really cool.
I had crashes on the billing screen, because the validate function for the card number is changing the focus to the expiration date field (if the card number is correct). This does not work right on the following case:
Type a correct card number
Type a correct expiration date
Click on the card number field : Crash!. At this point we change the firstResponder to the expiration date field again, and RxSwift goes crazy.
Other topic. I find reactive programming really good to tie a model with a view. What I don´t see now are the advantages of using it for validation. Using text field delegates you have an entry point for all the changes happening on the text field. Maybe you can save some if statements, but nothing more. Or I am missing something? :S.
Thank you for that update @arodriguezju - I appreciate the time you took to figure that out! Good example of how sometimes the memory management with Rx can get a little hairy if youâre not careful.
I know one of the big things I run into trouble with in my day to day work is validating multiple UITextField forms when using traditional MVC / Delegate methods. When performing the âShould I allow the user to submit this data?â logic, I either wind up with a giant if/else statement in my delegate method deciding which validation to run based on what field has changed, or performing validation on every field every time anything in any field changes, which is a giant waste of the userâs battery.
To me, the advantage of using Rx for validation over traditional delegate methods is that youâre able to avoid having to run your validation on every field every time anything changes - only when that field changes do you need to update its boolean for validity, and then when all the booleans are updated, that automatically flips on the button which allows you to submit. No field needs to know anything else about the validity of any other field, and when that field changes, only its own validation is run without the need for a large, hideous if/else statement, or having to check a very large number of booleans manually.
Thanks for this great tutorial. Here I am struggling with a crash. Once I filled all the details i.e. Credit card number, expiry date and cvv. After this purchase button got enabled. Then I again went to Credit card number field and app crashes. I tried to debug the cause of crash but failed. If anyone could help me would be great.
What happens when you crash? Have you added an exception breakpoint to your project?
If nothing happens when you crash - no console output, no opportunity to examine variables - then you probably need to add an exception breakpoint. Go to the breakpoint navigator (shortcut: â7) and then click the â+â at the bottom corner of the screen, then choose add exception breakpoint. Next time you crash you will hopefully be able to a little more information that will help you debug the problem.