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 a Playlist Browser with Swift Building the Master and Detail Views Displaying Playlist Information

Tyler Banks
Tyler Banks
3,109 Points

Build a playlist browser with Swift, displaying playlist information

Hi, I was following the steps in the video, all was good till minute 2:13, Pasan runs the app after some modifications and works, mine does not, even though I strictly followed the steps in the video, I'm getting this error: (line 2 , Thread 1: signal SIGABRT)

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate { (Thread 1: signal SIGABRT) -> "This is the message"

    var window: UIWindow?



This is my code:

class PlaylistDetailViewController: UIViewController {

    var playlist: Playlist?

    @IBOutlet weak var playlistCoverImage: UIImageView!
    @IBOutlet weak var playlistTitle: UILabel!
    @IBOutlet weak var playlistDescription: UILabel!


    override func viewDidLoad() {
        super.viewDidLoad()

        if playlist != nil {
            playlistCoverImage.image = playlist!.icon
            playlistCoverImage.backgroundColor = playlist!.backgroundColor
            playlistTitle.text = playlist!.title
            playlistDescription.text = playlist!.description

        }

    }

}

3 Answers

Hi Tyler,

As you can see, there's a problem with the dictionary or, at least, accessing it. That's all happened by the time your code reaches what you've posted there, I think. The issue might be hiding inside playlist.swift so it might be useful if you post that code too.

Steve.

Tyler Banks
Tyler Banks
3,109 Points

Hi Steve, thanks for replying, here is the playlist.swift code:

import Foundation
import UIKit

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]

        let colorsDictionary = playListDictionary["backgroundColor"] as [String: CGFloat]
        backgroundColor = rgbColorFromDictionary(colorsDictionary)

    }

    func rgbColorFromDictionary(colorDictionary: [String: CGFloat]) -> UIColor {

        let red = colorDictionary["red"]!
        let green = colorDictionary["green"]!
        let blue = colorDictionary["blue"]!
        let alpha = colorDictionary["alpha"]!

        return UIColor(red: red/255.0, green: green/255.0, blue: blue/255.0, alpha: alpha)
    }
}

Hi Tyler,

I'm struggling to see much wrong with that. Have you tried Product | Clean to see if that fixes it?

Failing that, my working code can be found at Github here - have a look!

I'm wondering if the issue is a corrupt dictionary in MusicLibrary.swift or something wrong in the MasterViewController. The only thing that I can see different, and I don't think it will make any difference at all, is that in one class, playlist is typed as playList but that seems consistently applied.

Let me know how you get on.

Steve.

Tyler Banks
Tyler Banks
3,109 Points

Hi, the problem was that I had a label with 2 referenced outlets to, all is working fine now ;)

Error displayed was "Thread 1: signal SIGABRT" just in case...

Tyler.

Ah right, yes. That's really easy to do if you do the drag & drop twice and forget to delete the first one.

Glad you got it sorted.

Steve.