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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:30:08+00:00 2026-05-24T07:30:08+00:00

Hey I’m trying to learn Objective-C and Cocoa Dev, but I’m having problems with

  • 0

Hey I’m trying to learn Objective-C and Cocoa Dev, but I’m having problems with making a Calculator App with a GUI. Here are my two files for my AppController class

AppController.h

    #import <Cocoa/Cocoa.h>

@interface AppController : NSObject
{
    IBOutlet NSTextField *textField1;
    IBOutlet NSTextField *textField2;
    IBOutlet NSTextField *resultsField;
}

- (IBAction)add:(id)sender;
- (IBAction)multiply:(id)sender;
- (IBAction)subtract:(id)sender;
- (IBAction)divide:(id)sender;

@end

AppController.m

#import "AppController.h"

int addx(int x, int y)
{
    return (x+y);
}

int subtractx(int x, int y)
{
    return (x-y);
}

int multiplyx(int x, int y)
{
    return (x*y);
}

int dividex(int x, int y)
{
    return (x/y);
}


@implementation AppController

- (void) awakeFromNib
{
    [textField1 setStringValue:@"Enter first value here"];
    [textField2 setStringValue:@"Enter second value here"];
    [resultsField setStringValue:@"Results come out here"];
}

- (IBAction)add:(id)sender
{
    NSInteger *value1;
    value1 = [textField1 integerValue];

    NSInteger *value2;
    value2 = [textField2 integerValue];

    [resultsField setIntegerValue:addx(value1, value2)];
}

- (IBAction)subtract:(id)sender
{
    NSInteger *value1;
    value1 = [textField1 integerValue];

    NSInteger *value2;
    value2 = [textField2 integerValue];

    [resultsField setIntegerValue:subtractx(value1, value2)];
}

- (IBAction)multiply:(id)sender
{
    NSInteger *value1;
    value1 = [textField1 integerValue];

    NSInteger *value2;
    value2 = [textField2 integerValue];

    [resultsField setIntegerValue:multiplyx(value1, value2)];
}

-(IBAction)divide:(id)sender
{
    NSInteger *value1;
    value1 = [textField1 integerValue];

    NSInteger *value2;
    value2 = [textField2 integerValue];

    [resultsField setIntegerValue:dividex(value1, value2)];
}


@end

Everything works fine except Add. For some reason The program crashes whenever I try to use Add. All the other functions work fine, but they are identical to each other. Why is this happening? Can someone please help me? I thank you in advance.

  • 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-24T07:30:09+00:00Added an answer on May 24, 2026 at 7:30 am

    You are using NSInteger* (pointer to NSInteger) to store variables that should simply be NSInteger. Try the following:

    - (IBAction)add:(id)sender
    {
        NSInteger value1 = [textField1 integerValue];
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey having some trouble trying to maintain transparency on a png when i create
Hey guys, am trying to write to do type casting in java, but i
Hey, I'm trying to get the source code of an app similar to the
Hey I'm trying to figure out a regular expression to do the following. Here
Hey guys im making a c++ game and im trying to load a bitmap
Hey all. Newbie question time. I'm trying to setup JMXQuery to connect to my
Hey, I need to do my drawing over a panel in C# but without
Hey guys I have a query that selects data and organizes but not in
Hey I am getting this error: error: conversion to non-scalar type requested Here are
Hey I'm building an app that will allow a user to log into a

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.