consolidate if statements into single lines, cleanup
MODIFY
Podcast/BookmarkViewController.swift
Podcast/BookmarkViewController.swift
@@ -40,22 +40,18 @@ class BookmarkViewController: UIViewController, UITableViewDelegate, UITableView
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
- }
-
- override func viewDidAppear(_ animated: Bool) {
- super.viewDidAppear(animated)
// check before reloading data whether the Player has stopped playing the currentlyPlayingIndexPath
- if let indexPath = currentlyPlayingIndexPath {
- if let card = cards[indexPath.row] as? EpisodeCard {
- if Player.sharedInstance.currentEpisode?.id != card.episode.id {
+ if let indexPath = currentlyPlayingIndexPath, let card = cards[indexPath.row] as? EpisodeCard, Player.sharedInstance.currentEpisode?.id != card.episode.id {
currentlyPlayingIndexPath = nil
}
- }
- }
bookmarkTableView.reloadData()
}
+ override func viewDidAppear(_ animated: Bool) {
+ super.viewDidAppear(animated)
+ }
+
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
@@ -110,18 +106,13 @@ class BookmarkViewController: UIViewController, UITableViewDelegate, UITableView
func cardTableViewCellDidPressPlayPauseButton(cardTableViewCell: CardTableViewCell) {
- guard let cardIndexPath = bookmarkTableView.indexPath(for: cardTableViewCell), let card = cards[cardIndexPath.row] as? EpisodeCard else { return }
-
- if cardIndexPath == currentlyPlayingIndexPath { return }
+ guard let cardIndexPath = bookmarkTableView.indexPath(for: cardTableViewCell), let card = cards[cardIndexPath.row] as? EpisodeCard, cardIndexPath != currentlyPlayingIndexPath, let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
- if let indexPath = currentlyPlayingIndexPath {
- if let cell = bookmarkTableView.cellForRow(at: indexPath) as? CardTableViewCell {
+ if let indexPath = currentlyPlayingIndexPath, let cell = bookmarkTableView.cellForRow(at: indexPath) as? CardTableViewCell {
cell.setPlayButtonToState(isPlaying: false)
}
- }
currentlyPlayingIndexPath = cardIndexPath
cardTableViewCell.setPlayButtonToState(isPlaying: true)
- let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.showPlayer(animated: true)
Player.sharedInstance.playEpisode(episode: card.episode)
}

MODIFY
Podcast/FeedViewController.swift
Podcast/FeedViewController.swift
@@ -48,22 +48,18 @@ class FeedViewController: UIViewController, UITableViewDelegate, UITableViewData
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
- }
-
- override func viewDidAppear(_ animated: Bool) {
- super.viewDidAppear(animated)
// check before reloading data whether the Player has stopped playing the currentlyPlayingIndexPath
- if let indexPath = currentlyPlayingIndexPath {
- if let card = cards[indexPath.row] as? EpisodeCard {
- if Player.sharedInstance.currentEpisode?.id != card.episode.id {
+ if let indexPath = currentlyPlayingIndexPath, let card = cards[indexPath.row] as? EpisodeCard, Player.sharedInstance.currentEpisode?.id != card.episode.id {
currentlyPlayingIndexPath = nil
}
- }
- }
feedTableView.reloadData()
}
+ override func viewDidAppear(_ animated: Bool) {
+ super.viewDidAppear(animated)
+ }
+
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
@@ -118,18 +114,13 @@ class FeedViewController: UIViewController, UITableViewDelegate, UITableViewData
func cardTableViewCellDidPressPlayPauseButton(cardTableViewCell: CardTableViewCell) {
- guard let cardIndexPath = feedTableView.indexPath(for: cardTableViewCell), let card = cards[cardIndexPath.row] as? EpisodeCard else { return }
-
- if cardIndexPath == currentlyPlayingIndexPath { return }
+ guard let cardIndexPath = feedTableView.indexPath(for: cardTableViewCell), let card = cards[cardIndexPath.row] as? EpisodeCard, cardIndexPath != currentlyPlayingIndexPath, let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
- if let indexPath = currentlyPlayingIndexPath {
- if let cell = feedTableView.cellForRow(at: indexPath) as? CardTableViewCell {
+ if let indexPath = currentlyPlayingIndexPath, let cell = feedTableView.cellForRow(at: indexPath) as? CardTableViewCell {
cell.setPlayButtonToState(isPlaying: false)
}
- }
currentlyPlayingIndexPath = cardIndexPath
cardTableViewCell.setPlayButtonToState(isPlaying: true)
- let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.showPlayer(animated: true)
Player.sharedInstance.playEpisode(episode: card.episode)
}

consolidate if statements into single lines, cleanup