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 trialDan Rolnik
122 PointsWhat's wrong with my code
Mistake message: "Bummer! Remember to use the keyword 'self' to access the 'quotes' property and initialize it with the 3 quotes mentioned above."
My code in THViewController.m:
#import "THViewController.h"
@implementation THViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.quotes =
[[NSArray alloc] initWithObjects: @"Haters gonna hate", @"Life is simple, not easy",
@"Winners never quit, quitters never win", nil];
// Add your code below!
// Remember the array property is called 'quotes'
// And the label property is called 'quoteLabel'
}
@end
I allocated and initialized quotes with those quotes what else I supposed to do?
4 Answers
Stone Preston
42,016 Pointshmm try submitting it again. your code is correct. I just passed using your alloc and init code. below is the full .m file
#import "THViewController.h"
@implementation THViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.quotes = [[NSArray alloc] initWithObjects: @"Haters gonna hate", @"Life is simple, not easy", @"Winners never quit, quitters never win", nil];
// Add your code below!
// Remember the array property is called 'quotes'
// And the label property is called 'quoteLabel'
}
Dan Rolnik
122 PointsThanks, but I just copied the wrong one.
#import "UIViewController.h"
#import "UILabel.h"
@interface THViewController : UIViewController
@property (nonatomic, strong) IBOutlet UILabel *quoteLabel;
@property (nonatomic,strong) NSArray *quotes;
@end
Still same mistake: "Remember to use the keyword 'self' to access the 'quotes' property and initialize it with the 3 quotes mentioned above."
Stone Preston
42,016 Pointsman im really not sure what the problem is. Everything you have looks good. could just be something weird going on with the engine. I just passed task 2 with this .h
#import "UIViewController.h"
#import "UILabel.h"
@interface THViewController : UIViewController
@property (nonatomic, strong) IBOutlet UILabel *quoteLabel;
@property (nonatomic,strong) NSArray *quotes;
@end
and this .m
#import "THViewController.h"
@implementation THViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Add your code below!
// Remember the array property is called 'quotes'
// And the label property is called 'quoteLabel'
self.quotes = [[NSArray alloc] initWithObjects: @"Haters gonna hate", @"Life is simple, not easy", @"Winners never quit, quitters never win", nil];
}
@end
Dan Rolnik
122 PointsThank you, Stone, for your help.
I think I found the problem, I inserted code above comments ant they asked to do it below O_o
So stupid mistake :)
Thank you again!
Stone Preston
42,016 Pointsno I tried that as well thinking that might have been it and passed haha (check out the .m file in my first answer, i put the code above the comments as well) . I also tried adding the space between nonatomic in strong thinking that could have been it and it passed as well. not really sure what the deal is
Dan Rolnik
122 PointsYour last code worked. No idea what went wrong) Thanks
Stone Preston
42,016 Pointsim not really sure what happened either. your original code looked correct to begin with so Im pretty sure it wasnt an error on your part, but it could have been. Oh well, you are passed it now
Dan Rolnik
122 PointsDan Rolnik
122 PointsThis is challenge's task: The random quotes app needs an array of quotes. Declare a property named 'quotes'. Make it an NSArray and use the modifiers 'nonatomic' and 'strong'.
Maybe I forgot something?
Stone Preston
42,016 PointsStone Preston
42,016 Pointspost the code you used for the header file property declaration. You could have messed that up and caused task 2 not to pass for some reason.
Dan Rolnik
122 PointsDan Rolnik
122 PointsTHViewController.h
P.S Also tried your code. it makes mistake:"Make sure you are creating a property named 'quotes' with the right modifiers!"
Stone Preston
42,016 PointsStone Preston
42,016 Pointsyou need to add an NSArray property called quotes with the nonatomic and strong attributes.