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 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.