views:

44

answers:

1

Hi

I've defined a new type with this code

typedef enum result 
{

     error,
     error1,
     erorr2,

}result;

After that I want to implement a method that takes a "result" as parameter

- (void) setError:(result)errorNumber

It seems that it is not allowed and give me an compiler error.

Is not possible to use user defined type as method parameters?!?

+1  A: 

You need to import the header file that contains the typedef before you use it. For example:

File1.h:

typedef enum { a, b, c } resultType;

File2.h:

#import "File1.h"

...


- (void) someMethod:(resultType)param;

File1.h can be imported into as many header (or implementation) files as you need.

Stephen Darlington
sorry write mistake- (void) setTError:(result)errorNumber;but also in this case it return me an error
Luca
@Luca Where is your typedef? Is it in the same file? What is the compiler error message?
Stephen Darlington
The complier errore compare only if i try to use my user defined type ad parameter of a method in another .h files. I' ve imported the .h file with the type declaration...is not possible to use that in another file thah import the header with the typedef? thanks
Luca
@Luca I've changed my answer (and your question) to reflect the new information you added.
Stephen Darlington
@Luca Also, in general you should include the actual error message rather than just say that there was one.
Stephen Darlington