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 trialScott Baumbich
Courses Plus Student 22,129 PointsError 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 '?')
1 Answer
Scott Baumbich
Courses Plus Student 22,129 PointsI 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)