Welcome to the Treehouse Community
Looking to learn something new?
Jan Veldhuis3,371 Points
How to use the Playlist struct in a tableView
As a side project I'm trying to use the Playlist/MusicLibrary struct combi from this video to fill up a tableview. Basically I'm trying to get tableViewCells using the title from the MusicLibrary.
However, it doesn't work yet. Part of the problem seems to be that I cannot do a proper count on the Playlist struct. When I do this:
var playlist: [Playlist] =  playlist.count
I get a count of 0, while it should be 6 (the six different entries in the MusicLibrary.
Any pointers on what I should do?? Help is greatly appreciated.
Looking at your code, there are several things that are not going to work as you intend them to. From what I get, you want to create a UITableView that contains some information from the library .. am I right ?
First.. look at your init method, what are you initializing there ? You are passing an index of type Int.. for what? If you try to create an instance of that struct, it will give you back an error.
Second.. The .count method is returning 0 because you are creating an empty array of type PersonalDetailsStruct.
Third.. When you want to work with UITableViews, you have to follow the MVC paradigm. That's very important.
Lastly, this implementation or this code was meant for a different purpose, you might want to create your own struct with your own library, meant for a UItableView.
If you want to start your own code, and need guidance on it, I can help you. Just let me know.