Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Build a Playlist Browser with Objective-C Managing Playlist Data Creating UIImageViews

durul dalkanat
durul dalkanat
62,690 Points

Managing Playlist Data Challenge Task 2 of 3

My code block is below. What is my problem ?

_profileImageName = [friendsDict objectForKey:@"profileImage"]; UIImage *profileImage = [UIImage imageNamed:_profileImageName];

Treehouse.h
#import <Foundation/Foundation.h>

@interface Treehouse : NSObject

@property (strong, nonatomic) NSDictionary *friends;

@end
Treehouse.m
#import "Treehouse.h"

@implementation Treehouse

- (instancetype)init
{
    self = [super init];
    if (self) {
        _friends = @{@"firstName": @"Susan",
                     @"lastName": @"Olson",
                     @"profilePicture": @"susan_profile.png"
                     };
    }
    return self;
}



@end
User.h
#import <Foundation/Foundation.h>

@interface User : NSObject

@property (nonatomic, strong) NSString *firstName;
@property (nonatomic, strong) NSString *lastName;
@property (nonatomic, strong) NSString *profileImageName;
@property (nonatomic, strong) UIImage * profileImage;
@property (nonatomic, strong) UIImageView *userProfilePhoto;

@end
User.m
#import "User.h"
#import "Treehouse.h"

@implementation User

- (instancetype)init
{
    self = [super init];
    if (self) {
        Treehouse *treehouse = [[Treehouse alloc] init];
        NSDictionary *friendsDict = treehouse.friends;

        _firstName = [friendsDict objectForKey:@"firstName"];
        _lastName = [friendsDict objectForKey:@"lastName"];

        _profileImageName = [friendsDict objectForKey:@"profileImage"];
        UIImage *profileImage = [UIImage imageNamed:_profileImageName];
    }
    return self;
}

@end

4 Answers

Bradley Maskell
Bradley Maskell
8,858 Points
- (instancetype)init
{
    self = [super init];
    if (self) {
        Treehouse *treehouse = [[Treehouse alloc] init];
        NSDictionary *friendsDict = treehouse.friends;

        _firstName = [friendsDict objectForKey:@"firstName"];
        _lastName = [friendsDict objectForKey:@"lastName"];
        _profileImageName = [friendsDict objectForKey:@"profilePicture"];

        _profileImage = [UIImage imageNamed:_profileImageName];
        _userProfilePhoto = [[UIImageView alloc] initWithImage:_profileImage];

        //Enter your code below!
    }
    return self;
}
eric hughes
eric hughes
12,345 Points

did you end up figuring it out, im stuck on this right now

eric hughes
eric hughes
12,345 Points

OF COURSE! thank you so much!

How did you end up doing the last challenge. Im completely lost on that part. https://teamtreehouse.com/forum/creating-instance-of-uiimageview