I'm trying to get an example from Hillegass' Cocoa Programming for Mac OS X book to run, and I keep getting an I'm NSInternalInconsistencyException , though I'm not sure why.
The purpose of the app is to show how Key-Value Coding can be binded (bound?) to an application.
Here's my code:
Code:
//
// AppController.h
//
#import <Cocoa/Cocoa.h>
@interface AppController : NSObject {
double fido;
}
- (id)init;
- (double)fido;
- (void)setFido:(double)x;
@end
//
// AppController.m
//
#import "AppController.h"
@implementation AppController
- (id)init
{
[super init];
[self setValue:[NSNumber numberWithDouble:5]
forKey:@"fido"];
NSNumber* number = [self valueForKey:@"fido"];
NSLog(@"fido: %@",number);
return self;
}
- (double)fido
{
NSLog(@"-fido is returning %d", fido);
return fido;
}
- (void)setFido:(double)x
{
NSLog(@"-setFido: is called with %d", x);
fido = x;
}
@end
In Interface Builder, I'm simply dragging a vertical slider to the default .nib window, and checking "Continuous" "Bind to: AppController" (<- the name of OOP object I've created).
Fido was initially an int, but I changed it to a double because I was getting an exception:
Code:
2009-10-10 19:21:43.126 KVCFun[5084:10b] An uncaught exception was raised
2009-10-10 19:21:43.127 KVCFun[5084:10b] Cannot create double from object <AppController: 0x130700> of class AppController
2009-10-10 19:21:43.128 KVCFun[5084:10b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Cannot create double from object
The problem is, whenever I run it, I get the follow exception thrown:
Code:
2009-10-10 19:22:38.403 KVCFun[5113:10b] Cannot create double from object <AppController: 0x130700> of class AppController
2009-10-10 19:22:38.404 KVCFun[5113:10b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Cannot create double from object <AppController: 0x130700> of class AppController'
Any suggestions as to what could be wrong?