Bummer! You have been redirected as the page you requested could not be found.

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

Swift: Struct Initialization project has errors

I'm watching the struct initialization video in the course for making a playlist browser in Swift. I was pretty sure I followed the tutorial exactly, and I had errors in the Playlist file. I downloaded the project and opened it in Xcode, and there were errors in there too. When I type:

title = playlistDictionary["title"] as String! 

I get the error,

'(String, NSObject)' is not convertible to 'String'

I pasted the full struct below.

struct Playlist {

var title: String?
var description: String?
var icon: UIImage?
var largeIcon: UIImage?
var artists: [String] = []
var backgroundColor: UIColor = UIColor.clearColor()

init(index: Int) {
    let musicLibrary = MusicLibrary().library
    let playlistDictionary = musicLibrary[index]

    title = playlistDictionary["title"] as String!
    description = playlistDictionary["description"] as String!

    let iconName = playlistDictionary["icon"] as String!
    icon = UIImage(named: iconName)

    let largeIconName = playlistDictionary["largeIcon"] as String!
    largeIcon = UIImage(named: largeIconName)

    artists += playlistDictionary["artists"] as [String]

}

}

5 Answers

Your code is correct. Can you post the code of your detailViewController (where you actually call the title) ?

This is my DetailViewController. I don't think I call the title from here.

class PlaylistDetailViewController: UIViewController {


    @IBOutlet weak var buttonPressLabel: UILabel!
    var segueLabelText: String = ""

    override func viewDidLoad() {
        super.viewDidLoad()

        buttonPressLabel.text = segueLabelText

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

http://oi57.tinypic.com/2hyc3s0.jpg

Thanks Daniel

I figured it out...

hi brendan, i am having the same error - could you tell me how you fixed this? thanks!

Sorry, I never figured out the actual problem. I ended up starting over and got it working again. I really don't know what was wrong with it.

started over from where? the very beginning of the playlist browser tutorial?

so how can we correct the code?

hi sam did you figure out how to correct the code?