Building Spotify App in Swift 5 & UIKit - Part 11 (Xcode 12, 2021, Swift 5) - Build App
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let section = sections[indexPath.section]
switch section {
case .newReleases(viewModels: let viewModels):
let album = newAlbums[indexPath.row]
let albumVC = AlbumViewController(album: album)
albumVC.title = album.name
albumVC.navigationItem.largeTitleDisplayMode = .never
navigationController?.pushViewController(albumVC, animated: true)
break
...
}
import UIKit
class AlbumViewController: UIViewController {
private let album: Album
private var albumDetail: AlbumDetailsResponse?
init(album: Album) {
self.album = album
super.init(nibName: nil, bundle: nil)
}
required init?(coder: NSCoder) {
fatalError()
}
override func viewDidLoad() {
super.viewDidLoad()
fetchData()
setAlbumViewUI()
}
private func setAlbumViewUI() {
title = album.name
view.backgroundColor = .systemBackground
}
private func fetchData() {
APICaller.shared.getAlbumDetails(for: album) { result in
switch result {
case .success(let model):
self.albumDetail = model
break
case .failure(let error):
print(error.localizedDescription)
break
}
}
}
}