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 6761073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:08:34+00:00 2026-05-26T14:08:34+00:00

I have been reading numerous books on iPhone development and doing the examples but

  • 0

I have been reading numerous books on iPhone development and doing the examples but I notice the idea of MVC is not really being taught correctly (although the authors do say that Xcode “lends itself” to the MVC way of coding).

A quick example. I want to make a simple calculator app (as many who are starting out do).

I have a working version with all of my code inside the xxxxxViewController.m file. Actions and Outlets all working well. The trouble with this approach is if I want to have multiple views (normal calculator and scientific calculator) I would have copy and paste my code so I now have two versions. I am clearly trying to avoid this.

So, I have created my own class (based on NSObject) as my CalculatorEngine.

Trouble is when trying to allocate and initialise my CalculatorEngine I receive errors such as “Redefinition of CalculatorEngine with a different type” and “Type specifier missing, defaults to int”.

I guess I am missing something obvious.

Can you point me in the direction of a sample of any kind where a separate class is being used as an “engine” rather than having the code inside the xxxxViewController?

At this point the code below does not actually do anything. I am just trying to get the CalculatorEngine object useable in CalculatorViewController.m. This is where I receive the error.

//  CalculatorAppDelegate.h
//  Calculator

#import <UIKit/UIKit.h>

@class CalculatorViewController, CalculatorEngine;

@interface CalculatorAppDelegate : NSObject <UIApplicationDelegate>

@property (nonatomic, retain) IBOutlet UIWindow *window;

@property (nonatomic, retain) IBOutlet CalculatorViewController *viewController;

@end




//  CalculatorAppDelegate.m
//  Calculator

#import "CalculatorAppDelegate.h"

#import "CalculatorViewController.h"

@implementation CalculatorAppDelegate

@synthesize window = _window;
@synthesize viewController = _viewController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
}

- (void)applicationWillResignActive:(UIApplication *)application
{
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
}

- (void)applicationWillTerminate:(UIApplication *)application
{
}

- (void)dealloc
{
}

@end




//  CalculatorViewController.h
//  Calculator

#import <UIKit/UIKit.h>

@interface CalculatorViewController : UIViewController

@end




//  CalculatorViewController.m
//  Calculator

#import "CalculatorViewController.h"
#import "CalculatorEngine.h"

@implementation CalculatorViewController

// This was wrong here. Now moved to viewDidLoad().
//CalculatorEngine *CalcEng;
//CalcEng = [[CalculatorEngine alloc] init];

// trouble here. CalcEng is unknow.
-(IBAction)buttonPressed:(id)sender {
    [CalcEng setRegisterX:1];
}

- (void)viewDidLoad
{
    CalculatorEngine *CalcEng;
    CalcEng = [[CalculatorEngine alloc] init];
    [super viewDidLoad]
}

- (void)didReceiveMemoryWarning
{
}

- (void)viewDidUnload
{
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
}

@end




//  CalculatorEngine.h
//  Calculator

#import <Foundation/Foundation.h>

@interface CalculatorEngine : NSObject

@end




//  CalculatorEngine.m
//  Calculator

#import "CalculatorEngine.h"

@implementation CalculatorEngine

- (id)init
{
    self = [super init];
    if (self) {
        // Initialization code here.
    }

    return self;
}

@end
  • 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-05-26T14:08:35+00:00Added an answer on May 26, 2026 at 2:08 pm

    This code is in the wrong location:

    CalculatorEngine *CalcEng;
    CalcEng = [[CalculatorEngine alloc] init];
    

    Put that into -(void)viewDidLoad.

    UPDATE
    You cannot call your method because your view controller is not keeping a reference to the CalcEngine (by the way, variables like this should be camel cased to keep in line with naming conventions, so it would be calcEngine). To keep a reference you need to add an iVar, or more appropriately, a property called CalcEngine. To do this, your CalculatorViewController header would look like this:

    //  CalculatorViewController.h
    //  Calculator
    
    #import <UIKit/UIKit.h>
    
    @interface CalculatorViewController : UIViewController {
       CalculatorEngine *CalcEngine;
    }
    
    @property (retain) CalculatorEngine *CalcEngine;
    @end
    

    Your implementation would look like this:

    //  CalculatorViewController.m
    //  Calculator
    
    #import "CalculatorViewController.h"
    #import "CalculatorEngine.h"
    
    @implementation CalculatorViewController
    
    // This was wrong here. Now moved to viewDidLoad().
    //CalculatorEngine *CalcEng;
    //CalcEng = [[CalculatorEngine alloc] init];
    
    // trouble here. CalcEng is unknow.
    -(IBAction)buttonPressed:(id)sender {
        [CalcEng setRegisterX:1];
    }
    
    - (void)viewDidLoad
    {
        CalcEng = [[CalculatorEngine alloc] init];
        [super viewDidLoad]
    }
    
    - (void)didReceiveMemoryWarning
    {
    }
    
    - (void)viewDidUnload
    {
    }
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
    }
    
    @end
    

    Don’t take this the wrong way, but you should spend some time reading Apple’s Objective C guide. The problems you are having have nothing to do with MVC, but with objective-c.

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

Sidebar

Related Questions

I have been reading the Phing documentation and it makes sense, but I'm not
I have been reading so many topics here about this, but I could not
I have been reading up on multiple PHP frameworks, especially the Zend Framework but
I have been reading SO for some time now, but I truly cannot find
I have been reading about exception handling on the Apple developer docs , but
I have been reading about how read.table is not efficient for large data files.
I have been reading a lot about openFrameworks and Processing, But still can't make
I have been reading the rsync documentation for a few hours, but I can't
I have been reading the AVFoundation docs and I have just not been able
I have been reading many posts that describe my problem but I cannot find

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.