Note that there are some explanatory texts on larger screens.

plurals
  1. POiPhone - Architecture for viewController and network requests
    primarykey
    data
    text
    <p>So, I have 2 types of data, some needs to be persisted and some doesn't.</p> <p>I'm thinking about where to put all my network related code, inside my UIViewControllers, where all the network request start from, or in a another layer.</p> <p>What I had in mind is this:</p> <p>Have a layer called <code>NetworkManager</code>. <code>NetworkManager</code> is singerlton to all my web service calls.</p> <p>For data that needs to be persistent and can be presented in a list, I would have network manager issues the request, save the response in my local core data DB, and have my <code>UIViewController</code> listen to that data using <code>FetchResultsController</code>.</p> <p>But, there's many other types of requests. For example : login request, user info request, friendsNearBy, and so on… some don't have to be persistent in my db, and some don't fit the FRC architecture.</p> <p>For these type of request, as far as I see, there are 2 ways of handling it:</p> <p><strong>1.</strong> Have another layer that separates between the ViewControllers and the NetworkManager. Let's call it <code>Mediator</code>. The <code>Mediator</code> gets the dictionary(JSON) request from the networkManager, decides according to the app logic if there's anything else needs to be done with it, and then post a notification with appropriate name and data. If the mediator saves the UIViewController who issued the request, it can delegate the response directly to him instead of posting a notification.</p> <p>The Flow would be like this:</p> <pre><code>MyUiViewController - &gt; Mediator -&gt; NetworkManger-&gt;Mediator-&gt; PostNotification (or directly back to MyUiViewController) Pros: Decoupling Nice structure and separation of concerns Cons: Harder to code Sometimes harder to understand and debug. </code></pre> <p><strong>2.</strong> Not having this 3 layered architecture, but instead having MyUiViewControllers, issue a network request with blocks. Meaning instead of the Mediator intercepting the response before MyUiViewController, just let MyUiViewController handle the response using blocks as he is the one that issues it.</p> <pre><code>Pros: Simple and quick to code Easy to understand Cons: Coupling of network code inside your controllers </code></pre> <p><em>I was hoping to get suggestions and comments about what's best from people's experience, or other/better way of doing this.</em></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload