Apologies
You must be signed in to watch this lesson.
Download Episodes JSONEncoder Decoder
Podcasts
Podcasts are extremely useful for when you are stuck somewhere without internet connection and have nothing to do to pass the time. Allowing users to download each podcast for later offline playback is a wonderful feature that every user will appreciate. In today's lesson, let's reuse a previous controller to display potential episodes we download into our app.

Comments (12)
Tube
6 years ago
BONUS EPISODE? I can tell you are getting excited about wrapping up this course. I think this is your best course ever. You really have a marvelous knack for this; so, I hope you never tire of it. I want to request a bonus episode showing us--or at least getting us started--playing video podcasts! For a future course, I want to suggest a functional--not just an UI--ePub reader. Great course!
Brian Voong
6 years ago
ayon
6 years ago
Hi brain tx a lot for these awesome videos. I have a small feedback to share. If you search ex. Daily show with trevor noah, u will see that theres some <p> tage <p> coming in the description section and I have also checked out the json data, the podcast doesn't have any feedURL. If u can enlighten me how to fix it, it would be really great.
Brian Voong
6 years ago
ayon
6 years ago
tx man, it helped
syedfa
5 years ago
Hi Brian, thanks so much once again for putting together such a comprehensive course. I may have discovered a bug here that you may have overlooked, and I apologize if this is my oversight: It appears that I'm allowed to download an episode of a particular podcast multiple times (i.e. we are not checking for duplicates). If I continuously swipe an episode from the EpisodesController UITableView, and click download each time, and then go to the DownloadsController, I see the multiple downloads that I've made. I'm bringing this up because you did not list this as one of the challenges at the end of this episode. Could you provide a fix for this? Thanks once again for your hard work!
syedfa
5 years ago
func downloadEpisode(episode: Episode) { do { var episodes = downloadedEpisodes() if episodes.isEmpty { episodes.append(episode) } else { if !episodes.contains(where: { $0.title == episode.title && $0.author == episode.author }) { episodes.insert(episode, at: 0) } } let data = try JSONEncoder().encode(episodes) UserDefaults.standard.set(data, forKey: UserDefaults.downloadedEpisodesKey) } catch let encodeErr { print("Failed to encode episode: ", encodeErr) } }
syedfa
5 years ago
The above is the fix that I implemented :-)
rehannali
5 years ago
Hi Brain! I've very quick question. You declare globlly variable for episodes and fro refresh data you overwrite again with same line to refresh list. Correct me if i'm wrong. I think it is dupication. What if we only place that line in viewWillAppear and after that reload data?
rehannali
5 years ago
I think i found an answer to my question. We need Global variable to use in tableview delegate to layout data.
Akarys Turganbekuly
5 years ago
Hi Brian! I know this question will be out of topic, but i really need help. Beside learning from the course I'm doing side project with Odoo.com They provide API with XML-RPC. If it's possible could you please help me to figure out how to implement that?
Dew Douglass
5 years ago
You should do a video showing all the behind the scenes work you do to make each one of these videos. Do you use a version control or something to move ahead in code then come back for the tutorial?
Brian Voong
5 years ago
Dew Douglass
5 years ago
So does this JSONDecoder perform the same function as NSKeyedUnarchiver or is it different?
Brian Voong
5 years ago
Dew Douglass
5 years ago
The challenges are a great idea. You should incorporate those as much as possible!
inboxforapps@gmail.com
5 years ago
How can we download the video files for offline viewing?
awjenson
5 years ago
Hi. In func downloadEpisodes(), how did you know to construct JSONDecoder() to get JSONDecoder().decode(type: Decoable.Protocol, from: Data)? I only ask because I was accidentally writing my code as JSONDecoder.decode(self: JSONDecoder) and it took me a minute to notice I need to construct the JSONDecoder. Thanks!
awjenson
5 years ago
Hi. Why do we sometimes add .self after a Type? Example: [Episode].self
Brian Voong
5 years ago
Katlego
5 years ago
Brian you're fire bro!
HELP & SUPPORT