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


Kieran Tross
Kieran Tross
8,266 Points

arc4random_uniform with dictionaries with two data types

Hi All!

I'm currently working on a project that produces random shapes(triangle, circle, pentagon, etc). The app will display a random shape with 4 buttons below. One of the 4 buttons has an association with the random shape image. Does anyone know how I can write out a function that does the random dictionary value with a image and string data type. I've pasted the code I have so far but I keep getting an error message because my "key" data type is an image.

func randomImage() -> UIImage {

    let index: Int = Int(arc4random_uniform(UInt32(myImages.count)))
    let value = Array(myImages.values)[index]
    let key = Array(myImages.keys)[index]

    return (key, value!)