Refactoring to a Data Manager

In this episode we clean up some autolayout warnings, implement some changes to support dynamic text, then move our attention to presenting the podcast detail screen when tapping on search results. Since the data is coming from various places we introduce a Data Manager to move that responsibility out of the view controller.

Episode Links

Cleaning Up The AutoLayout Warning

To better understand the warnings shown by auto layout, we can use WTFAutolayout.com. By pasting the error log, we get the visual representation of errors occurred during auto layout.

Creating Podcast Loading Errors

We will create an enum PodcastLoadingError to handle all the related errors while loading the data. It converts the API error into the loading error with a meaningful description assigned to each one of them.

Moving Recommended Search To PodcastDataManager

To get the details of a podcast for the podcast detail screen, we require the feed. However only one of the current API responses has a feedURL property. We will have to add some logic to fetch the feed URL first if we need it, then fetch the feed itself. Since the view controller displays the data from various sources we can move this responsibility to a PodcastDataManager. This allows the data manager to decide the source of the data to be displayed in the podcast detail screen.

Adding LookUp for Search Result without FeedURL

We will now display our detailed view of the selected search result in SearchViewController. For the results containing feedURL, we will display the details for the selected feed, in the cases where the result does not have feedURL we will have to lookup in the data manager to get the feedURL.

Fixing Header issue while the required data is missing

Displaying the detail view may not be correct when an expected data is missing in the selected search. To resolve this, we will clear all the properties to nil and disables the subscribeButton. Do enable the subscribeButton while updating UI.