iOS Design Patterns - Part 5: Multicast Closure | Ray Wenderlich

@jrg.developer Hi Joshua, In MVVM video, I don’t see where you place the code for networking. Where should it be? in MVVM?

@jrg.developer Can you please help with this when you get a chance? Thank you - much appreciated! :]

In some projects, I have seen developers put networking directly code into the ViewModel (that is, using NSURLSession, etc directly in the ViewModel).

Personally, however, I don’t like this because it violates the Single Responsibility Principle. That is, the view model is doing at least two things: view transformations (that’s what view models do, after all) and networking.

Instead, I propose that Model-View-Controller-Networking (MVC-N) is a better pattern for networking. Wherein, you pull out networking code into it’s own “networking client” class.

I actually cover this pattern in this video series:

https://videos.raywenderlich.com/courses/72-ios-design-patterns/lessons/3

Once you have a separate “networking client” class, you can then choose where its appropriate to put calls to the networking client. This ultimately depends on your project’s specific use-case, but most likely, you’ll wind up putting this in either the View Controller or View Model.

There really isn’t a “best choice” on which to do here
 Rather, you should think about why you want to put calls to networking in one versus the other and run it through each of the SOLID principles. If it doesn’t break any SOLID principles, you’re probably okay. If it does break a SOLID principle, you should consider what the long-term consequences will be, and if you’re okay with them or not.

For example, if you break “Single Responsibility”, will this lead to a huge class later on? Will it result in you duplicating code later on? Etc.

If you’d like to learn more about SOLID, I highly recommend this book:

Clean Coding by Robert Martin

This video can not be played back. I’ve waited more than 10 minutes, but I’m still buffering. I’m in Seoul, South Korea. My internet speed is so fast but It is not be played
 Please check.

@yoshiboarder It actually works for me after all, so please go ahead and try to play it again when you get a chance. Thank you!