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 Build a Simple iPhone App with Swift Creating a Data Model Creating a Data Collection

Omotayo Olawepo
Omotayo Olawepo
2,803 Points

Hey, is it possible to store an image in the array as opposed to the text

Hey, is it possible to store an image in the array as opposed to the text

2 Answers

Yes, you can store images instead of strings in an array. You can store any object you like in an array.

import UIKit

var images: [UIImage] 

This will create a variable array that stores UIImages. To change it to any other type of object, you just have to replace UIImage with the name of the object you would like it to contain.

you can read about loading images to an UIImage in the apple docs UIImage

Omotayo Olawepo
Omotayo Olawepo
2,803 Points

Hi i tried using it but i keep getting contextual type UIImage cannot be used with array literal . i'm guessing i don't know how to reference the image files properly:/

here what i have so far import UIKit struct dicing { let firstDices: UIImage = ["Dice 1","Dice-2", ]

}