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 Introduction to Table Views Sorting Contacts Into Sections Custom Prototype Cells

Stephen Wall
PLUS
Stephen Wall
Courses Plus Student 27,294 Points

I can't seem to reference that Star image in code.

My Xcode cant see the Star icon from the assets folder in code. Is there a way to fix this? If not is there a work around?

Hey i have a same problem, do you fixed it?

Ryan McArthur
Ryan McArthur
3,683 Points

I had this same problem in the Interactive Story. It works if you enter

#imageLiteral(resourceName: "Star")

in place of the reference.

If you copy the references like that into another text editor, I guess that's the code underneath. As to why it's not finding the reference in the same way in the video, I'm really not sure, but if someone else knows, I'd be interested to know.

In Swift 5 and above, you can use either of the commented out lines

if contact.isFavorite {
            //contactCell.favoriteIcon.image = UIImage(imageLiteralResourceName: "Star")
            //contactCell.favoriteIcon.image = UIImage(named: "Star")
            //contactCell.favoriteIcon.image = #imageLiteral("Star") //Should Autocompleted with the image
        }

1 Answer

One other note, you can punch in #imageLiteral or just start typing image literal and select it and a generic image icon will appear. Double click that icon and you can then select the image. Seems like a weird new system but that works at least.