0

I've recently began trying to write my first iPhone app and I'm having some issues running it and I'm not sure what is going on here. Sorry if this is a dumb noob mistake. Mainly I do not have any errors or warning in my code so I'm confused to why this is happening. If anyone could help that would be great!

Console Output:

2014-06-05 18:45:23.563 1RMCalculator[2239:60b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ViewController 0x1095242c0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key reps.'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010194a495 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x00000001016a999e objc_exception_throw + 43
    2   CoreFoundation                      0x00000001019ce919 -[NSException raise] + 9
    3   Foundation                          0x000000010128a530 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 259
    4   CoreFoundation                      0x0000000101946400 -[NSArray makeObjectsPerformSelector:] + 224
    5   UIKit                               0x00000001004b18a6 -[UINib instantiateWithOwner:options:] + 1131
    6   UIKit                               0x000000010034bb0c -[UIViewController _loadViewFromNibNamed:bundle:] + 245
    7   UIKit                               0x000000010034c149 -[UIViewController loadView] + 112
    8   UIKit                               0x000000010034c3b7 -[UIViewController loadViewIfRequired] + 75
    9   UIKit                               0x000000010034c777 -[UIViewController view] + 29
    10  UIKit                               0x000000010028c96b -[UIWindow addRootViewControllerViewIfPossible] + 58
    11  UIKit                               0x000000010028cc70 -[UIWindow _setHidden:forced:] + 282
    12  UIKit                               0x0000000100295ffa -[UIWindow makeKeyAndVisible] + 51
    13  UIKit                               0x0000000100251c98 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1788
    14  UIKit                               0x0000000100255a0c -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 660
    15  UIKit                               0x0000000100266d4c -[UIApplication handleEvent:withNewEvent:] + 3189
    16  UIKit                               0x0000000100267216 -[UIApplication sendEvent:] + 79
    17  UIKit                               0x0000000100257086 _UIApplicationHandleEvent + 578
    18  GraphicsServices                    0x0000000103ac371a _PurpleEventCallback + 762
    19  GraphicsServices                    0x0000000103ac31e1 PurpleEventCallback + 35
    20  CoreFoundation                      0x00000001018cc679 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 41
    21  CoreFoundation                      0x00000001018cc44e __CFRunLoopDoSource1 + 478
    22  CoreFoundation                      0x00000001018f5903 __CFRunLoopRun + 1939
    23  CoreFoundation                      0x00000001018f4d83 CFRunLoopRunSpecific + 467
    24  UIKit                               0x00000001002552e1 -[UIApplication _run] + 609
    25  UIKit                               0x0000000100256e33 UIApplicationMain + 1010
    26  1RMCalculator                       0x0000000100002883 main + 115
    27  libdyld.dylib                       0x0000000101fe25fd start + 1
    28  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

ViewController.m

#import "ViewController.h"

@interface ViewController ()

@property (strong, nonatomic) IBOutlet UITextField *weightField;
@property (strong, nonatomic) IBOutlet UITextField *repsField;
@property (weak, nonatomic) IBOutlet UIButton *nintyFiveResult;
@property (weak, nonatomic) IBOutlet UIButton *nintyResult;
@property (weak, nonatomic) IBOutlet UIButton *eightyFiveResult;
@property (weak, nonatomic) IBOutlet UIButton *eightyResult;
@property (weak, nonatomic) IBOutlet UIButton *seventyFiveResult;
@property (weak, nonatomic) IBOutlet UIButton *seventyResult;
@property (weak, nonatomic) IBOutlet UIButton *sixtyFiveResult;
@property (weak, nonatomic) IBOutlet UIButton *sixtyResult;

@end

@implementation ViewController

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

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

- (IBAction)weightModified:(UITextField *)sender {

    if([self.weightField.text isEqualToString:(@"0")] == false && [self.repsField.text isEqualToString:(@"0")] == false){

        // Gather reps and weight value
        int reps = 0;
        int weight = 0;
        weight = [sender.text intValue];
        reps = [self.repsField.text intValue];

        int nintyFiveInt = [self oneRepMax :0.95 :reps :weight];
        int nintyInt = [self oneRepMax :0.9 :reps :weight];
        int eightyFiveInt = [self oneRepMax :0.85 :reps :weight];
        int eightyInt = [self oneRepMax :0.8 :reps :weight];
        int seventyFiveInt = [self oneRepMax :0.75 :reps :weight];
        int seventyInt = [self oneRepMax :0.7 :reps :weight];
        int sixtyFiveInt = [self oneRepMax :0.65 :reps :weight];
        int sixtyInt = [self oneRepMax :0.6 :reps :weight];

        NSString *nintyFiveWeight = [NSString stringWithFormat:@"95%%: %d", nintyFiveInt];
        NSString *nintyWeight = [NSString stringWithFormat:@"95%%: %d", nintyInt];
        NSString *eightyFiveWeight = [NSString stringWithFormat:@"95%%: %d", eightyFiveInt];
        NSString *eightyWeight = [NSString stringWithFormat:@"95%%: %d", eightyInt];
        NSString *seventyFiveWeight = [NSString stringWithFormat:@"95%%: %d", seventyFiveInt];
        NSString *seventyWeight = [NSString stringWithFormat:@"95%%: %d", seventyInt];
        NSString *sixtyFiveWeight = [NSString stringWithFormat:@"95%%: %d", sixtyFiveInt];
        NSString *sixtyWeight = [NSString stringWithFormat:@"95%%: %d", sixtyInt];

        [self.nintyFiveResult setTitle:nintyFiveWeight forState:UIControlStateNormal];
        [self.nintyResult setTitle:nintyWeight forState:UIControlStateNormal];
        [self.eightyFiveResult setTitle:eightyFiveWeight forState:UIControlStateNormal];
        [self.eightyResult setTitle:eightyWeight forState:UIControlStateNormal];
        [self.seventyFiveResult setTitle:seventyFiveWeight forState:UIControlStateNormal];
        [self.seventyResult setTitle:seventyWeight forState:UIControlStateNormal];
        [self.sixtyFiveResult setTitle:sixtyFiveWeight forState:UIControlStateNormal];
        [self.sixtyResult setTitle:sixtyWeight forState:UIControlStateNormal];
    }
}

- (IBAction)repsModified:(UITextField *)sender {

    if([self.weightField.text isEqualToString:(@"0")] == false && [self.repsField.text isEqualToString:(@"0")] == false){

        // Gather reps and weight value
        int reps = 0;
        int weight = 0;
        weight = [sender.text intValue];
        reps = [self.repsField.text intValue];

        int nintyFiveInt = [self oneRepMax :0.95 :reps :weight];
        int nintyInt = [self oneRepMax :0.9 :reps :weight];
        int eightyFiveInt = [self oneRepMax :0.85 :reps :weight];
        int eightyInt = [self oneRepMax :0.8 :reps :weight];
        int seventyFiveInt = [self oneRepMax :0.75 :reps :weight];
        int seventyInt = [self oneRepMax :0.7 :reps :weight];
        int sixtyFiveInt = [self oneRepMax :0.65 :reps :weight];
        int sixtyInt = [self oneRepMax :0.6 :reps :weight];

        NSString *nintyFiveWeight = [NSString stringWithFormat:@"95%%: %d", nintyFiveInt];
        NSString *nintyWeight = [NSString stringWithFormat:@"95%%: %d", nintyInt];
        NSString *eightyFiveWeight = [NSString stringWithFormat:@"95%%: %d", eightyFiveInt];
        NSString *eightyWeight = [NSString stringWithFormat:@"95%%: %d", eightyInt];
        NSString *seventyFiveWeight = [NSString stringWithFormat:@"95%%: %d", seventyFiveInt];
        NSString *seventyWeight = [NSString stringWithFormat:@"95%%: %d", seventyInt];
        NSString *sixtyFiveWeight = [NSString stringWithFormat:@"95%%: %d", sixtyFiveInt];
        NSString *sixtyWeight = [NSString stringWithFormat:@"95%%: %d", sixtyInt];

        [self.nintyFiveResult setTitle:nintyFiveWeight forState:UIControlStateNormal];
        [self.nintyResult setTitle:nintyWeight forState:UIControlStateNormal];
        [self.eightyFiveResult setTitle:eightyFiveWeight forState:UIControlStateNormal];
        [self.eightyResult setTitle:eightyWeight forState:UIControlStateNormal];
        [self.seventyFiveResult setTitle:seventyFiveWeight forState:UIControlStateNormal];
        [self.seventyResult setTitle:seventyWeight forState:UIControlStateNormal];
        [self.sixtyFiveResult setTitle:sixtyFiveWeight forState:UIControlStateNormal];
        [self.sixtyResult setTitle:sixtyWeight forState:UIControlStateNormal];
    }
}

- (int)oneRepMax:(int) percent :(int) numReps :(int) weightToLift{

    return percent*(weightToLift*(numReps/30));
}

@end

If curious I'm creating a basic 1RM calculator. I figured it would be something easy for a starting point. The page has two text fields and eight buttons.

  • That error doesn't look like it's coming from this code. The error says that you're writing something like `[someObject setValue:something forKey:@"reps"]`, and that object is a ViewController rather than whatever you think it's supposed to be. – Chuck Jun 05 '14 at 23:10

2 Answers2

2

This issue is most likely related to interface builder. Did you shuffle around any IBOutlets and perhaps leave one orphaned? If everything looks in order then perhaps you deleted one and just need to do a clean build. Go to the Xcode Organizer > Projects > "Delete" Derived Data. Then perform a clean build and see if that fixes the problem.

Dima
  • 23,484
  • 6
  • 56
  • 83
0

Another thing to check? Do you have any "User Defined Runtime Attributes" set on any of your views in interface builder? (They are shown in the "Identity Inspector" for each view. If those specify properties of your objects that don't exist, you will get this error.

It's not likely for a newbie to be using that feature, but maybe you were following a tutorial that showed you how to do it. It's at least worth mentioning.

Duncan C
  • 128,072
  • 22
  • 173
  • 272