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 Refactoring Our Code Adding Multiple Playlists

Getting error: "fatal error: unexpectedly found nil while unwrapping an Optional value"

Unfortunately on runtime the error above keeps appearing on various part of the application.

I managed to get rid of it once before but it is now showing up on the line:

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

I'm wondering if anyone can shed some further light on what may be going on.

Thanks :)

How do you have your artists array defined?

Robin Malhotra
Robin Malhotra
14,883 Points

I means that the value of swift playlistDictionary["artists"] was nil on unwrapping. You may not have properly initialised the dict.

Jens Hagfeldt
Jens Hagfeldt
16,548 Points

It worked fine for me when only replacing all instances of (as) with (as!) in MusicLibrary.swift... because it was there you got the warnings before the error, was it not?

1 Answer

Thanks for the answers everyone.

I'll have a look and report back when I get chance :)