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.
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:
Note the “+” on the method definition
Also the typo(?) where you had the class definition of
queryDatabase, but the class implementation ofsimple