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

  • Home
  • SEARCH
  • 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 7498799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:36:04+00:00 2026-05-29T19:36:04+00:00

I am having a problem figuring out how to simply return an integer from

  • 0

I am having a problem figuring out how to simply return an integer from a method.

Here is what I have:

simple.h

@interface simple : NSObject {
}
- (int)simpleMethod;
@end

simple.m

#import "simple.h"
@implementation simple
- (int)simpleMethod {
    return 0;
}
@end

simpleViewController.m

- (IBAction)simpleButtonPressed:(id)sender {
    int test = [simple simpleMethod];
}

I am getting a warning on the line “int test…” that says, “simple may not respond to ‘+simpleMethod'”. And another warning that says, “Initialization makes integer from pointer without cast”.

My program is crashing on this line, so although this is just a warning it seems to be a problem.

I want to be able to use “simpleMethod” without creating an instance of the class “simple”. Is this possible?

Problem fixed: changed the – to a + as per Peter’s suggestion.

  • 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-29T19:36:06+00:00Added an answer on May 29, 2026 at 7:36 pm

    Currently you have simpleMethod defined as an instance method. But to do what you want to do, you need to define the method as a class method:

    @interface simple : NSObject {
    }
    + (int)simpleMethod;
    @end
    
    #import "simple.h"
    @implementation simple
    + (int)simpleMethod {
        return 0;
    }
    @end
    
    - (IBAction)simpleButtonPressed:(id)sender {
        int test = [simple simpleMethod];
    }
    

    Note the “+” on the method definition

    Also the typo(?) where you had the class definition of queryDatabase, but the class implementation of simple

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

Sidebar

Related Questions

I am having trouble figuring out one implementation problem, I have one class, it
I am having a bit of a problem here. I have two int values,
I'm having a bit of a problem figuring out how to get the X/Y
I'm having a hard time figuring this problem out - I am trying to
I'm having trouble figuring out what my Flex Project is expecting from my PHP
I'm having a problem figuring out how to represent a many-to-many relationship model in
I am having a problem figuring out how to solve this problem the Django
I'm having a problem figuring out how to initiate an array of struct pointers.
I'm having a bit of trouble figuring out something that should be simple. I
I am still having problems with figuring out how to create winforms in 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.