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 trialDavid Fry
13,267 PointsWhat am I doing wrong?
"Within the loadLocation method allocate and initialize the locationManager property which has been declared in the header file. After initializing don't forget to set the delegate property to self."
.h file:
#import "UIViewController.h"
@interface THEntryViewController : UIViewController <CLLocationManagerDelegate>
@property (nonatomic, strong) CLLocationManager *locationManager;
- (void)loadLocation;
@end
.m file:
#import "THEntryViewController.h"
@implementation THEntryViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Rest of viewDidLoad code omitted
[self loadLocation];
}
- (void)loadLocation {
// Allocate and initialize the `locationManager` property which is declared in the header
self.locationManager = [[CLLocationManager alloc]init];
self.locationManager.delegate = self;
}
@end
3 Answers
Holger Liesegang
50,595 PointsHi David,
self.locationManager = [[CLLocationManager alloc]init];
self.locationManager.delegate = self;
seems to be ok and I don't know why it's not working for you, but this solution for Challenge task 1 of 3 "Within the loadLocation method allocate and initialize the locationManager property which has been declared in the header file. After initializing don't forget to set the delegate property to self." should work:
#import "THEntryViewController.h"
@implementation THEntryViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Rest of viewDidLoad code omitted
[self loadLocation];
}
- (void)loadLocation {
// Allocate and initialize the `locationManager` property which is declared in the header
self.locationManager = [CLLocationManager new];
self.locationManager.delegate = self;
}
@end
David Fry
13,267 PointsHmm.. here is the error I am getting: "cannot find protocol declaration for 'CLLocationManagerDelegate' @interface THEntryViewController : UIViewController ^ 1 error generated."
Holger Liesegang
50,595 PointsHave you tried to Copy&Paste
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
into the loadLocation method?
And yes, the <CLLocationManagerDelegate> protocol declaration is missing in the header file but that would be only a problem in Xcode and not this challenge...
Holger Liesegang
50,595 PointsHolger Liesegang
50,595 PointsI just tested your solution
and it passed the challenge without a problem...