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

Download and attach a photo from the init method of a struct

I have a struct

struct Person { let name: String var addresses: [Address] var phones: [Phone] var urls: [URL] let photoUrl: URL var photo: UIImage? var emails: [Email] var socialMedia: [Channel] }

My struct has a photoUrl. During the initI am trying to download the photo and assign it to the photo attribute of the struct. Is there a better way to accomplish this, or am I just not seeing the path to accomplishing this. The end goal is to have an array of persons that I will hand to a Table View.

Do I have to assign the photo from outside of the struct?

I am assuming that you have the types declared somewhere else in your code. The easiest way to accomplish this is to create a Plist and access the information through there. If you have not already; watch the course on Swift table views and it should all make sense on how to accomplish this

I have completed the course. I am re-watching all the videos to find what I missed. I think what I need to do is write a function that includes an escaping completion handler. Still, it won't hurt to go over the lessons again.

[Edit:] OMG, I didn't thank you. Thank you for helping point me in the right direction!