xcode instance help!

Discussion in 'Mac Apps and Mac App Store' started by Istrfly, Sep 14, 2004.

  1. Istrfly macrumors newbie

    Sep 14, 2004
    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?
  2. SilentPanda Moderator emeritus


    Oct 8, 2002
    The Bamboo Forest
    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:

    Class B could have the following

    A = new A;

    However it could not have:


    Unless myPrivateMethod was in class B instead.

    That would be my guess as to your problem.
  3. HexMonkey Administrator


    Staff Member

    Feb 5, 2004
    New Zealand
    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 */
    #import <Cocoa/Cocoa.h>
    @interface ConverterController : NSObject
        IBOutlet id converter;
        IBOutlet NSTextField *dollarField;
        IBOutlet NSTextField *rateField;
        IBOutlet NSTextField *totalField;
    - (IBAction)convert:(id)sender;
    #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];
    /* Converter */
    #import <Cocoa/Cocoa.h>
    @interface Converter : NSObject
    - (float)convertAmount:(float)amt atRate:(float)rate;
    #import "Converter.h"
    @implementation Converter
    - (float)convertAmount:(float)amt atRate:(float)rate {
    	return (amt * rate);
  4. bousozoku Moderator emeritus

    Jun 25, 2002
    Gone but not forgotten.
    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.

Share This Page