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 trialRichard Price
2,050 PointsWhere to Start? Build a playlist
its time for another annoying challenge where you get to the end and feel you haven't learnt anything at all. Really tedious
anyway has anyone managed to do this challenge as I don't even know where to start
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let friends = Treehouse().friends
//Add your code below
}
}
struct Treehouse {
let friends = [
"firstName": "Susan",
"lastName": "Olson",
"profilePicture": "susan_profile.png"
]
}
1 Answer
tom barbour
3,865 PointsHi Richard,
The below solution should work:
let friends = Treehouse().friends
let profileImageName = friends["profilePicture"]!
let profilePicture = UIImage(named: profileImageName)
Just to expand - we've already created an instance of the Treehouse struct dictionary friends and called it friends. We then access the key profile picture and store the string in the constant profileImageName.
We can then pass profileImageName into the UIImage constant profilePicture to store our chosen image.
Caleb Kleveter
Treehouse Moderator 37,862 PointsCaleb Kleveter
Treehouse Moderator 37,862 PointsI tried this and it didn't work.
tom barbour
3,865 Pointstom barbour
3,865 PointsHi Caleb,
The solution above works ok for me.
Did you remember to unwrap using the '!' symbol?
Caleb Kleveter
Treehouse Moderator 37,862 PointsCaleb Kleveter
Treehouse Moderator 37,862 PointsWhich file do I put it in?
tom barbour
3,865 Pointstom barbour
3,865 Pointsshould all go in the ImageView file. No need to amend the Treehouse.swift file
Caleb Kleveter
Treehouse Moderator 37,862 PointsCaleb Kleveter
Treehouse Moderator 37,862 PointsOkay, I figured out my issue. I didn't realize that the challenge was for Swift, not Objective-C :).