View Full Version : xcode instance help!
Istrfly
Sep 14, 2004, 08:38 PM
Hello, I am new to this forum, but I cannot find any help. I was wondering if anyone knew why the currency converter tutorial comes up with this error when trying to run it.
2004-09-14 20:36:36.054 CurrencyConverter[1158] *** -[ConverterController convertAmount:atRate:]: selector not recognized
2004-09-14 20:36:36.057 CurrencyConverter[1158] *** -[ConverterController convertAmount:atRate:]: selector not recognized
Then nothing happens. I have checked again and again and my code is exactly like the tutorials. However... if I put a + instead of a - in front of the method, it works great. Can anyone please explain this?
Thanks!
SilentPanda
Sep 14, 2004, 09:07 PM
I'm pulling this from the "I did a few tutorials" memory so it might be wrong but I do know how to code (just not strong in Obj-C).
The - in Obj-C makes the function private to the class whereas the + makes it public to all. Most likely your function is in the wrong class. For example:
Class A has methods:
+myPublicMethod
-myPrivateMethod
Class B could have the following
A = new A;
A.myPublicmethod;
However it could not have:
A.myPrivateMethod;
Unless myPrivateMethod was in class B instead.
That would be my guess as to your problem.
HexMonkey
Sep 14, 2004, 11:01 PM
The - in Obj-C makes the function private to the class whereas the + makes it public to all.
No, the - represents an instance method and the + represents a static method.
I found a (working) copy of the tutorial that I did when I was learning Objective C, and it turns out that convertAmount:atRate: is a method of the Converter class, but the error you are getting suggests that the message is being sent to the ConverterController class. Check what objects you are sending the convertAmount:atRate: message to.
For reference, I've put a copy of the code from my copy below (hopefully it's the same version).
ConverterController.h:
/* ConverterController */
#import <Cocoa/Cocoa.h>
@interface ConverterController : NSObject
{
IBOutlet id converter;
IBOutlet NSTextField *dollarField;
IBOutlet NSTextField *rateField;
IBOutlet NSTextField *totalField;
}
- (IBAction)convert:(id)sender;
@end
ConverterController.m:
#import "ConverterController.h"
#import "Converter.h"
@implementation ConverterController
- (void)awakeFromNib {
[[rateField window] makeKeyAndOrderFront:self];
[rateField selectText:self];
}
- (IBAction)convert:(id)sender
{
float rate, amt, total;
amt = [dollarField floatValue];
rate = [rateField floatValue];
total = [converter convertAmount:amt atRate:rate];
[totalField setFloatValue:total];
[rateField selectText:self];
}
@end
Converter.h:
/* Converter */
#import <Cocoa/Cocoa.h>
@interface Converter : NSObject
{
}
- (float)convertAmount:(float)amt atRate:(float)rate;
@end
Converter.m:
#import "Converter.h"
@implementation Converter
- (float)convertAmount:(float)amt atRate:(float)rate {
return (amt * rate);
}
@end
bousozoku
Sep 14, 2004, 11:11 PM
Are you sure that the connections you drew in Interface Builder are correct?
The code could look fine but the hidden information would be pointing to/from the incorrect object in the pane.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.