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 Playlist Browser with Objective-C Managing Playlist Data Creating UIImageViews

cant seem to get out of this bind....im trying to finish the final task.

Im trying to finish the last part of this code...allocating and initializing with the image "_profileImage" that I have already created.

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"];


         NSString *imageFromFriendsDict = [friendsDict objectForKey: @"profilePicture"];
        _profileImageName =  imageFromFriendsDict;

        _profileImage = [UIImage imageNamed:_profileImageName];

       _userProfilePhoto =  [[_userProfilePhoto alloc] initWithImage:_profileImage];








    }
    return self;
}

@end

1 Answer

Sean Kingery
Sean Kingery
12,874 Points

Your'e trying to alloc and init it as a _userProfilePhoto instead of its type which is UIImageView. Try UIImageView instead of _userProfilePhoto.