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 trialJan Veldhuis
3,371 PointsHow to use the Playlist struct in a tableView
Hi guys,
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.
1 Answer
Jhoan Arango
14,575 PointsHey Jan:
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 ?
My observations:
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.
Jan Veldhuis
3,371 PointsThanks Jhoan, your pointers helped me solve it.
Please add me to the group too, I have some more pressing questions:)
Jhoan Arango
14,575 PointsSend me your e-mail, and I'll send you an invite.
Jhoan Arango
14,575 PointsJhoan Arango
14,575 PointsJan:
I may be able to help, but without a proper code on here, I am not sure what you are doing, trying to do or what is wrong with your code. So if you want to post the code here, or add it on a github repository, I may help you.