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

Nick Manring
Nick Manring
11,369 Points

_profileImage is not taking my code but I'm pretty sure it's right! Xcode says it is! :(

I am using

_profileImage = [UIImage imageNamed:_profileImageName];

after

_profileImageName = [friendsDict objectForKey:@"profilePicture"];

in this exercise and it's not taking. after re-creating this code exercise in Xcode it says it's right. I tried using profileImageName instead of _profileImageName before that, and Xcode changed it to have the underscore which made sense after thinking about. I don't understand. _profileImageName is a NSString, so it is just like the example in the previous video, but that it's not a local variable.... I wish you guys wouldn't switch up things like this and just ask us to re-create the video example but with different names... this is different because you are not asking to create a local variable first. confusing!

thank you!

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>
#import <UIKit/UIKit.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"];

        //Enter your code below!

        _profileImageName = [friendsDict objectForKey:@"profilePicture"];

        //Above is correct... what is wrong with below code????

        _profileImage = [UIImage imageNamed:_profileImageName];

    }
    return self;
}

@end

1 Answer

Nick Manring
Nick Manring
11,369 Points

So I refreshed my browser by accident. Afterwards, I retyped the first questions (the line above that assigns the name to _profileImageName and continued to the next (the one I was stuck on) and when I entered this same text above, it worked. Looks like the code challenge has some weird cache thing where you can't answer in different ways more than a couple times without it somehow thinking you are wrong no matter what?

all set! might be worth looking into though :P

thanks!