Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8731145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:09:52+00:00 2026-06-13T09:09:52+00:00

I’m trying to call a class method that is defined in an imported header

  • 0

I’m trying to call a class method that is defined in an imported header file.

When I run the code below, I get this error in the View on the “double *result = …” line:

+[CalculatorBrain runProgram:usingVariableValues:]: unrecognized selector sent to class 0x6908

** CalculatorViewController.m **

#import "CalculatorViewController.h"
#import "CalculatorBrain.h"

@interface CalculatorViewController()

@property (nonatomic, strong) CalculatorBrain *brain;
@property (nonatomic, strong) NSMutableDictionary *variableValues;

@end

@implementation CalculatorViewController

@synthesize brain = _brain;
@synthesize variableValues = _variableValues;

- (CalculatorBrain *)brain {
    if (!_brain) _brain = [[CalculatorBrain alloc] init];
    return _brain;
}

- (NSMutableDictionary *)variableValues {
    if (!_variableValues) {
        _variableValues = [[NSMutableDictionary alloc] init];
    }
    return _variableValues;
}

- (IBAction)enterPressed {

    double *result = [CalculatorBrain runProgram:[self.brain program] usingVariableValues:[self variableValues]];

}

** CalculatorBrain.h **

#import <UIKit/UIKit.h>

@interface CalculatorBrain : NSObject

+ (double *)runProgram:(id)program usingVariableValues:(NSDictionary *)variableValues;

@property (readonly) id program;


@end

** CalculatorBrain.m **

#import "CalculatorBrain.h"

@interface CalculatorBrain()
    @property (nonatomic, strong) NSMutableArray *programStack;
@end

@implementation CalculatorBrain

@synthesize programStack = _programStack;


... other code ...

+ (double)runProgram:(id)program :(NSDictionary *) usingVariableValues 
{

    NSLog(@"variableValues is %@", usingVariableValues);

    NSMutableArray *stack;

    if ([program isKindOfClass:[NSArray class]]) {

        stack = [program mutableCopy];

        NSLog(@"runProgram");

        // if vars are passed in
        if ([usingVariableValues isKindOfClass:[NSDictionary class]]) {

            NSLog(@"vars are passed in: %@", usingVariableValues);

            id obj;
            int index = 0;

            NSEnumerator *enumerator = [program objectEnumerator];

            // for every obj in programStack
            while ((obj = [enumerator nextObject])) {

                id varVal = [usingVariableValues objectForKey:(obj)];

                // test
                NSLog(@"usingVariableValues objectForKey:(obj) is %@", varVal);

                // if the obj is a variable key
                if (!varVal) {
                    varVal = 0;

                    NSLog(@"varVal is false");
                }

                NSLog(@"Replacing object at index %@ of stack with var %@", index, varVal);


                // replace the variable with value from usingVariableValues OR 0
                [stack replaceObjectAtIndex:(index) withObject:varVal];

                index += 1;

            }
        }

    }

    return [self popOperandOffStack:stack];
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:09:53+00:00Added an answer on June 13, 2026 at 9:09 am
    + (double *)runProgram:(id)program usingVariableValues:(NSDictionary *)variableValues;
    

    Is defined as a class method, but you call it as an object method

     double *result = [self.brain runProgram:[self.brain program] usingVariableValues:[self variableValues]];
    

    To call it on the class do:

     double *result = [[self.brain class] runProgram:[self.brain program] usingVariableValues:[self variableValues]];
    

    Or

    double *result = [CalculatorBrain runProgram:[self.brain program] usingVariableValues:[self variableValues]];
    

    You changed your code, indicating, that the method is still not found. Did you implement it?


    If it is implemented, then you might have to add the implementation file (aka .m) to the target in Xcode.

    By the way,: probably you want your method to return a double not a double*, a pointer to a double.


    your header has a signature:

    + (double *)runProgram:(id)program usingVariableValues:(NSDictionary *)variableValues;
    

    While your implementation has

    + (double)runProgram:(id)program :(NSDictionary *) usingVariableValues 
    

    They are not identical:

    1. The header promisses a pointer to a double to be returned. You don’t want that.

    2. They don’t even have the same name
      +runProgram:usingVariableValues: vs +runProgram::

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am doing a simple coin flipping experiment for class that involves flipping a
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I know there's a lot of other questions out there that deal with this
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to create an if statement in PHP that prevents a single post

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.