tags:

views:

21

answers:

1

I've used typedef enum in the past with method parameters and had no problem, but today I'm having problems...

h file

typedef enum
{   eGetVarious1,
eGetVarious2,
} eGetVarious; 

- (double)getVarious:(eGetVarious)eVar:(NSDate*)pDate;

an m file

alt text

+2  A: 

you're calling a class method, and declaring an instance method:

instance method:

- (double)getVarious:(eGetVarious)eVar:(NSDate*)pDate;

class method (may not use ivars or instance methods):

+ (double)getVarious:(eGetVarious)eVar:(NSDate*)pDate;

say you want this as an instance method, declare it like this:

    - (double)getVarious:(eGetVarious)eVar forDate:(NSDate*)pDate;

and if you were in the scope of implementation of an instance method, then this should work:

double result = [self getVarious:eGetVarious1 forDate:[NSDate date]];

note the reason compiler is reporting an error:

if it has not seen a particular objc selector and you use it, it assumes the undeclared selector's arguments take id (anonymous objc object).

also, enum type should not be promoted to a pointer (although 0 is ok). since the compiler saw no way to match what you're calling: [objc_class* getVarious:eGetVarious<enum_type> :NSDate*] it is right, because you should be calling it as:

General * anInstanceOfGeneral = /* something here */;
NSDate * date = /* something here */;
double result = [anInstanceOfGeneral getVarious:eGetVarious1 forDate:date];
Justin
@Jules: Although he didn't mention it explicitly, notice that Justin has replaced your bare colon before the lowestDate parameter with "forDate:". Although the bare colon is legal, you'll almost never see it used because it is far less readable than describing the parameter.
JeremyP