0

I am actually designing a simple app to make use of the core location to get the location details and at the same time, displaying the latitude and longitude. But when I run it, I get an error message as below:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key forLatitude.'

I have synthesised the properties too. I still do not know the exact reason as to why it is throwing up an error !

rajViewController.h

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface rajViewController : UIViewController <CLLocationManagerDelegate>


@property (weak, nonatomic) IBOutlet UILabel *latitudeLabel;

@property (weak, nonatomic) IBOutlet UILabel *longitudeLabel;
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;
- (IBAction)getCurrentLocation:(id)sender;

@end

rajViewController.m

@interface rajViewController (){
    CLLocationManager *locationManager;
    CLGeocoder *geo;
    CLPlacemark *placemark;
}


@end

@implementation rajViewController
//@synthesize placemark;
@synthesize latitudeLabel;
@synthesize longitudeLabel;

.
.
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    CLLocation *newPlace = [[CLLocation alloc]init];
    newPlace = [locations lastObject];
    NSLog(@"the latitude is : %f",newPlace.coordinate.latitude);
    if (newPlace!=nil){
        self.latitudeLabel.text = [NSString stringWithFormat:@"%f", newPlace.coordinate.latitude];
        self.longitudeLabel.text = [NSString stringWithFormat:@"%f",newPlace.coordinate.longitude];
    }

}

Any help would be much appreciated.

Thanks and Regards, Raj.

Raj0689
  • 73
  • 1
  • 1
  • 9
  • hi Raj the problem may be before initializing ur NSDictionary ur setting value for somekey in dictionary first check if it not create just create it @Raj0689 – Sugan S Apr 08 '13 at 13:11
  • Hi sugan ! Sorry.. But can you be little specific.. Since I am new to objective-C :( – Raj0689 Apr 08 '13 at 13:18
  • hi raj you are trying to set value for key in dictionary that is not created just put NSLog before setting value to dict if it is null(dict).Just do dictname=[[NSMutableDictionary alloc]init] k.let me know if u not get – Sugan S Apr 09 '13 at 04:26
  • or else just print your response in NSLog – Sugan S Apr 09 '13 at 04:27
  • http://stackoverflow.com/questions/11118135/how-do-i-solve-a-nsunknownkeyexception-setvalueforundefinedkey-not – Sugan S Apr 09 '13 at 04:50
  • Sorry Raj as @Progrmr point check Outlet connection http://www.logicfx.net/content/terminating-app-due-uncaught-exception-nsunknownkeyexception-reason-setvalueforundefinedkey – Sugan S Apr 09 '13 at 04:52
  • k raj let me know if u need nay other help @Raj0689 – Sugan S Apr 10 '13 at 09:08
  • your blogs also nice @Raj0689 – Sugan S Apr 10 '13 at 09:26
  • oh.. Thanks :) That was not updated for a long time though !! – Raj0689 Apr 10 '13 at 09:34

1 Answers1

0

Check your nib to see if you have some connection to outlet called forLatitude. It's not a core location problem, this is an outlet connection problem

progrmr
  • 75,956
  • 16
  • 112
  • 147
  • Thanks :) I even thought it might be the problem. So, designed it completely new and now it is Ok :) – Raj0689 Apr 10 '13 at 08:42