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.

iOS Build a Playlist Browser with Swift Building the Music Library and Playlist Models Using a Playlist Instance

Jeanne Merle
Jeanne Merle
3,390 Points

No image displayed

Hi, My program is running, but no image is displayed in the Image View. The container is just orange, with nothing in it. I have added a property "iconFile" if Playlist struct, that contains the name of the file ("coffee.pdf" in our case) ... var iconFile : String ... let iconName = playListDictionary["icon"] as String! self.iconFile = iconName ... and i use a println in the viewDidLoad method to see if the dictionary is ok, which seems to be the case. ... let playList = PlayList(index: 0) playlistImageView0.image = playList.icon println(playList.iconFile) ... "coffee.pdf" appears in the debugger, at the bottom left. But the image "coffee.pdf" does not appear in the View.

Can you tell me why ? Thanks ! I really would like to fix this before going further.

3 Answers

Jeanne Merle
Jeanne Merle
3,390 Points

Ok I have looked in the Internet and found the solution here : http://stackoverflow.com/questions/24049537/defining-the-file-a-uiimage-will-use-swift

the right parameter to create an Image with a file name is : UIImage(named: String) rather than UIImage(contentsOfFile: String)

and now it works !

thanks for your concern Greg, see U

Greg Kaleka
Greg Kaleka
39,019 Points

Ah cool - thanks for updating us! For future reference, it's very helpful to actually see your code. Check out "Tips for asking questions" in the right sidebar ->

Greg Kaleka
Greg Kaleka
39,019 Points

Hi Jeanne,

I think you might want coffee.png, rather than coffee.pdf.

Let me know if that works!

-Greg

Jeanne Merle
Jeanne Merle
3,390 Points

Hi Greg, I'll try at home this evening, but I've pasted the exact same code as Pasan (in the "Teacher's notes" section), and it's "coffee.pdf". ++