0

I am struggling with an IOS app i literally just started. I followed this guide to the letter im sure

http://www.appcoda.com/how-to-get-current-location-iphone-user/

However in the main method i get the following error;

2013-12-04 20:28:55.591 MyLocationDemo[20391:c07] * Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key getLocation.' * First throw call stack: (0x1850012 0x116ce7e 0x18d8fb1 0xc18e41 0xb9a5f8 0xb9a0e7 0xbc4b58 0x2ce019 0x1180663 0x184b45a 0x2ccb1c 0x1917e7 0x191dc8 0x191ff8 0x192232 0xe13d5 0xe176f 0xe1905 0xea917 0xae96c 0xaf94b 0xc0cb5 0xc1beb 0xb3698 0x17abdf9 0x17abad0 0x17c5bf5 0x17c5962 0x17f6bb6 0x17f5f44 0x17f5e1b 0xaf17a 0xb0ffc 0x204d 0x1f75) libc++abi.dylib: terminate called throwing an exception

Does anyone know roughly what might be wrong with my code? The files I have modified are

//
//  main.m
//  MyLocationDemo
//

#import <UIKit/UIKit.h>

#import "MyLocationAppDelegate.h"
#import "MyLocationViewController.h"
int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([MyLocationAppDelegate class]));
    }
}


//
//  MyLocationViewController.h
//  MyLocationDemo
//

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>



@interface MyLocationViewController : UIViewController<CLLocationManagerDelegate>

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

@end

And this is where the main logic seems to be

//
//  MyLocationViewController.m
//  MyLocationDemo
//
//  Created by Ricki Lambert on 04/12/2013.
//  Copyright (c) 2013 Ricki Lambert. All rights reserved.
//

#import "MyLocationViewController.h"



@interface MyLocationViewController ()

@end

@implementation MyLocationViewController

CLLocationManager *locationManager;


- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    locationManager = [[CLLocationManager alloc] init];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)getLocation:(id)sender {
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;

    [locationManager startUpdatingLocation];
}

#pragma mark - CLLocationManagerDelegate

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
    NSLog(@"didFailWithError: %@", error);
    UIAlertView *errorAlert = [[UIAlertView alloc]
                               initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [errorAlert show];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    NSLog(@"didUpdateToLocation: %@", newLocation);
    CLLocation *currentLocation = newLocation;

    if (currentLocation != nil) {
        _longitudeLabel.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude];
        _latitudeLabel.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude];
    }
}
@end

EDIT:

Added the following code

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="2.0" toolsVersion="3084" systemVersion="12F37" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="2">
    <dependencies>
        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="2083"/>
    </dependencies>
    <scenes>
        <!--My Location View Controller-->
        <scene sceneID="5">
            <objects>
                <viewController id="2" customClass="MyLocationViewController" sceneMemberID="viewController">
                    <view key="view" contentMode="scaleToFill" id="3">
                        <rect key="frame" x="0.0" y="20" width="320" height="548"/>
                        <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                        <subviews>
                            <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Lattitude" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="2NQ-NG-XNs">
                                <constraints>
                                    <constraint firstAttribute="width" constant="114" id="3lT-6l-45k"/>
                                    <constraint firstAttribute="height" constant="34" id="NHO-Yt-dF0"/>
                                </constraints>
                                <fontDescription key="fontDescription" type="system" pointSize="17"/>
                                <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
                                <nil key="highlightedColor"/>
                            </label>
                            <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Longiude" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="RLl-n5-tOv">
                                <constraints>
                                    <constraint firstAttribute="width" constant="75" id="6AR-qh-Gnd"/>
                                    <constraint firstAttribute="height" constant="27" id="m84-iE-ZY7"/>
                                </constraints>
                                <fontDescription key="fontDescription" type="system" pointSize="17"/>
                                <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
                                <nil key="highlightedColor"/>
                            </label>
                            <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Address" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="1kJ-EE-aHk">
                                <constraints>
                                    <constraint firstAttribute="height" constant="27" id="6U9-sr-UXJ"/>
                                </constraints>
                                <fontDescription key="fontDescription" type="system" pointSize="17"/>
                                <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
                                <nil key="highlightedColor"/>
                            </label>
                            <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Lattitude goes here" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="fNS-Dr-1Vu">
                                <fontDescription key="fontDescription" type="system" pointSize="17"/>
                                <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
                                <nil key="highlightedColor"/>
                            </label>
                            <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Longitude goes here" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="NoA-nn-nJE">
                                <fontDescription key="fontDescription" type="system" pointSize="17"/>
                                <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
                                <nil key="highlightedColor"/>
                            </label>
                            <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Address goes here" lineBreakMode="tailTruncation" numberOfLines="4" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" preferredMaxLayoutWidth="158" translatesAutoresizingMaskIntoConstraints="NO" id="FRc-NM-7R7">
                                <constraints>
                                    <constraint firstAttribute="height" constant="110" id="Mxn-SQ-dDB"/>
                                    <constraint firstAttribute="width" constant="158" id="giI-DM-8Y6"/>
                                </constraints>
                                <fontDescription key="fontDescription" type="system" pointSize="14"/>
                                <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
                                <nil key="highlightedColor"/>
                            </label>
                            <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="tGJ-fU-7T9">
                                <constraints>
                                    <constraint firstAttribute="width" constant="194" id="wCV-5v-wAp"/>
                                </constraints>
                                <fontDescription key="fontDescription" type="boldSystem" pointSize="15"/>
                                <state key="normal" title="Get Address">
                                    <color key="titleColor" red="0.19607843459999999" green="0.30980393290000002" blue="0.52156865600000002" alpha="1" colorSpace="calibratedRGB"/>
                                    <color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
                                </state>
                                <state key="highlighted">
                                    <color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                                </state>
                                <connections>
                                    <action selector="getLocation:" destination="2" eventType="touchUpInside" id="4Gy-OZ-lTb"/>
                                </connections>
                            </button>
                        </subviews>
                        <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
                        <constraints>
                            <constraint firstAttribute="trailing" secondItem="FRc-NM-7R7" secondAttribute="trailing" constant="20" symbolic="YES" type="default" id="0Hn-nk-jah"/>
                            <constraint firstItem="FRc-NM-7R7" firstAttribute="top" secondItem="3" secondAttribute="top" constant="177" id="2a9-5q-b4n"/>
                            <constraint firstItem="NoA-nn-nJE" firstAttribute="top" secondItem="RLl-n5-tOv" secondAttribute="top" type="default" id="8xW-ST-2rJ"/>
                            <constraint firstItem="RLl-n5-tOv" firstAttribute="leading" secondItem="2NQ-NG-XNs" secondAttribute="leading" type="default" id="9D0-0e-Dab"/>
                            <constraint firstItem="1kJ-EE-aHk" firstAttribute="top" secondItem="3" secondAttribute="top" constant="174" id="Atx-uI-F5b"/>
                            <constraint firstAttribute="bottom" secondItem="tGJ-fU-7T9" secondAttribute="bottom" constant="131" id="GmZ-gM-2LB"/>
                            <constraint firstItem="1kJ-EE-aHk" firstAttribute="leading" secondItem="RLl-n5-tOv" secondAttribute="leading" type="default" id="Gyh-cL-XiN"/>
                            <constraint firstItem="tGJ-fU-7T9" firstAttribute="centerX" secondItem="3" secondAttribute="centerX" type="default" id="Tb3-0Y-di7"/>
                            <constraint firstItem="FRc-NM-7R7" firstAttribute="leading" secondItem="NoA-nn-nJE" secondAttribute="leading" type="default" id="U11-d2-DSe"/>
                            <constraint firstItem="RLl-n5-tOv" firstAttribute="top" secondItem="3" secondAttribute="top" constant="104" id="VdS-si-Rf1"/>
                            <constraint firstItem="fNS-Dr-1Vu" firstAttribute="top" secondItem="3" secondAttribute="top" constant="43" id="cM5-dt-7bh"/>
                            <constraint firstItem="2NQ-NG-XNs" firstAttribute="top" secondItem="3" secondAttribute="top" constant="37" id="mV7-Ff-Uuy"/>
                            <constraint firstItem="2NQ-NG-XNs" firstAttribute="leading" secondItem="3" secondAttribute="leading" constant="39" id="spa-RY-ZpM"/>
                            <constraint firstItem="1kJ-EE-aHk" firstAttribute="trailing" secondItem="RLl-n5-tOv" secondAttribute="trailing" type="default" id="x03-z0-I5T"/>
                            <constraint firstItem="NoA-nn-nJE" firstAttribute="leading" secondItem="fNS-Dr-1Vu" secondAttribute="leading" type="default" id="x1R-k4-2ns"/>
                        </constraints>
                    </view>
                    <connections>
                        <outlet property="addressLabel" destination="FRc-NM-7R7" id="oNw-qt-0yh"/>
                        <outlet property="getLocation" destination="tGJ-fU-7T9" id="69B-gi-HDF"/>
                        <outlet property="latitudeLabel" destination="fNS-Dr-1Vu" id="hTv-w4-7tN"/>
                        <outlet property="longitudeLabel" destination="NoA-nn-nJE" id="OxD-hl-qRK"/>
                    </connections>
                </viewController>
                <placeholder placeholderIdentifier="IBFirstResponder" id="4" sceneMemberID="firstResponder"/>
            </objects>
        </scene>
    </scenes>
    <classes>
        <class className="MyLocationViewController" superclassName="UIViewController">
            <source key="sourceIdentifier" type="project" relativePath="./Classes/MyLocationViewController.h"/>
            <relationships>
                <relationship kind="action" name="getLocation:"/>
                <relationship kind="outlet" name="addressLabel" candidateClass="UILabel"/>
                <relationship kind="outlet" name="getLocation" candidateClass="UIButton"/>
                <relationship kind="outlet" name="latitudeLabel" candidateClass="UILabel"/>
                <relationship kind="outlet" name="longitudeLabel" candidateClass="UILabel"/>
            </relationships>
        </class>
        <class className="NSLayoutConstraint" superclassName="NSObject">
            <source key="sourceIdentifier" type="project" relativePath="./Classes/NSLayoutConstraint.h"/>
        </class>
    </classes>
    <simulatedMetricsContainer key="defaultSimulatedMetrics">
        <simulatedStatusBarMetrics key="statusBar"/>
        <simulatedOrientationMetrics key="orientation"/>
        <simulatedScreenMetrics key="destination" type="retina4"/>
    </simulatedMetricsContainer>
</document>
Biscuit128
  • 5,218
  • 22
  • 89
  • 149

2 Answers2

0
<relationship kind="outlet" name="getLocation" candidateClass="UIButton"/>

This is causing your error, You create an getLocation outlet that does not point to anything in your ViewController.

To fix this:

  • Go to Utilies Pane(the right pane)
  • Select connection inspection(its the arrow ->)
  • remove reference to getLocation outlet
meda
  • 45,103
  • 14
  • 92
  • 122
0

In your storyboard do the following

  1. Select the controller
  2. Display the right panel
  3. click on connection inspector the last one on the right
  4. check on all the connection if anyone have an exclamation mark : then delete it

enter image description here

Hani Ibrahim
  • 1,448
  • 11
  • 21