Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Error Force Unwrapping Artist! (var artist = Artist!)
var artist = Artist!
is throwing the following error:
(Expected member name or constructor call after type nameAdd arguments after the type to construct a value of the type)
(Use '.self' to reference the type object)
(Using '!' is not allowed here; perhaps '?' was intended? Replace '!' with '?')
I managed to find a work around to this problem by explicitly declaring some fake data at initialization.
- THIS IS NOT A GOOD SOLUTION for many reasons but DOES allow you to continue with the lesson
//class AlbumListController: UITableViewController var artist : Artist = Artist(id: 1, name: "", primaryGenre: .pop, albums: [Album]())
NOTE: Later on in the video series, Pasan DOES go back and correct this. Turns out he did this intentinally to prove a point to NEVER force unwrap values.
If you want to see Pasan goes over the the solution in a much later lesson go ---> HERE (time stamp 11:05)
However, I advise you use my work around in your AlbumListController & similar in AlbumDetailController to further learn the content being taught
//class AlbumDetailController: UITableViewController var album: Album = Album(id: 0, artistName: "", name: "", censoredName: "", artworkUrl: "", isExplicit: false, numberOfTracks: 0, releaseDate: Date(), primaryGenre: .pop)