Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build An iTunes Search App Requesting Real Data Fetching A List of Songs

Emre Havan
Emre Havan
8,569 Points

Cant compile: Error: Value of type 'AlbumDetailDataSource' has no member 'update'

Hello all,

So my code on the "AlbumDetailController.swift" file is like following:

class AlbumDetailController: UITableViewController {

    var album: Album? {
        didSet {
            if let album = album {
                configure(with: album)
                dataSource.update(with: album.songs)
                tableView.reloadData()
            }
        }
    }


    var dataSource = AlbumDetailDataSource(songs: [])

    @IBOutlet weak var artworkView: UIImageView!
    @IBOutlet weak var albumTitleLabel: UILabel!
    @IBOutlet weak var albumGenreLabel: UILabel!
    @IBOutlet weak var albumReleaseDateLabel: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()

        if let album = album {
            configure(with: album)
        }

        tableView.dataSource = dataSource


    }

    func configure(with album: Album) {
        let viewModel = AlbumDetailViewModel(album: album)

        // Add implementation for artworkView
        albumTitleLabel.text = viewModel.title
        albumGenreLabel.text = viewModel.genre
        albumReleaseDateLabel.text = viewModel.releaseDate
    }

}

I dont know why but, on the line of

dataSource.update(with: album.songs)

I have an error telling me that AlbumDetailDataSource file has no member update, yes it does not and it does not have to have a member called update anyways. Since update member is created on 'AlbumListDataSource.swift" but it wants it to be at detaildatasource I guess... I'm new to ios and really could not figure out this. I dont know if I could explain briefly enough, but any help would be appreciated so much!

2 Answers

Alexander Zamudio
Alexander Zamudio
15,858 Points

Hi,

The update method that AlbumDetailDataSource is missing is similar to the one you use to update the albums. The function would not get added to the AlbumDetailController.swift, it would need to get added to AlbumDetailDataSource.swift

You need to add an update helper method in AlbumDetailDataSource . Thus your AlbumDetailDataSource.swift would look like this with the update function at the bottom:

class AlbumDetailDataSource: NSObject, UITableViewDataSource { private var songs: [Song]

init(songs: [Song]) {
    self.songs = songs
}

func numberOfSections(in tableView: UITableView) -> Int {
    return 1
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return songs.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: SongCell.reuseIdentifer, for: indexPath) as! SongCell

    let song = songs[indexPath.row]
    let viewModel = SongViewModel(song: song)

    cell.songTitleLabel.text = viewModel.title
    cell.songRuntimeLabel.text = viewModel.runtime

    return cell
}

func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
    switch section {
    case 0: return "Tracks"
    default: return nil
    }
}

// MARK - Helper

func update(with songs: [Song]) {
    self.songs = songs
}

}