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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![David Fry](https://uploads.teamtreehouse.com/production/profile-photos/619012/micro_david_profile.jpg)
David 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](https://secure.gravatar.com/avatar/114ef70406fce64fa70f90ad3e04ed09?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
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](https://uploads.teamtreehouse.com/production/profile-photos/619012/micro_david_profile.jpg)
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](https://secure.gravatar.com/avatar/114ef70406fce64fa70f90ad3e04ed09?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
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...