Stop repeating DispatchQueue.main.async
<p>The <code>MainQueueDecorator</code> acts as an interface between the <code>RemoteItemLoader</code> and the <code>ItemListController</code>, providing a neat way to handle main queue operations.</p>
<p>First, we define the <code>ItemService</code> protocol, which allows us to decouple our code from the concrete implementation of the <code>RemoteItemLoader</code>. This also gives us the flexibility to intercept the service and modify its behavior, such as in our case dispatching to the main queue.</p>
<p><iframe frameborder="0" height="104" scrolling="no" src="https://medium.com/media/0c75904e3d4a1e2bc73cbc7a6f310473" title="ItemService.swift" width="680"></iframe></p>
<p>Next, we make the <code>RemoteItemLoader</code> conform to the <code>ItemService</code> protocol.</p>
<p><iframe frameborder="0" height="478" scrolling="no" src="https://medium.com/media/efe82aaf079d17f526b2dd58fb92f114" title="RemoteItemLoader.swift" width="680"></iframe></p>
<p>We then replace the concrete class with the <code>ItemService</code> protocol in the <code>ItemListController</code>. This decouples the controller from the implementation details and allows us to work with the abstraction.</p>
<p><a href="https://medium.com/@krishnapalsinhgohil/remove-dispatchqueue-main-async-from-everywhere-and-simplify-1fc1c58e8fdf"><strong>Read More</strong></a></p>