Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

passing a enum as an argument in objective c

970 views
Skip to first unread message

mobabo

unread,
Nov 16, 2008, 1:28:39 AM11/16/08
to
I cannot figure out how to pass an instance of an enum as an argument.
If, for example, I have

enum Pet {Cat, Dog, Bird};

How should the prototype for a function that takes this as an argument
look? The following produced errors:

- (NSString) enumToString: (Pet) pet
error: syntax error before 'Pet'
- (NSString) enumToString: (enum Pet) pet
error: can not use an object as parameter to a method

Incidentally, I'm doing this to convert the enum's value into an
NSString.

John Whorfin

unread,
Nov 16, 2008, 1:42:37 AM11/16/08
to
mobabo wrote:
> I cannot figure out how to pass an instance of an enum as an argument.

It's not the enum (the second variant should work BTW), its the return
type being NSString instead of an "NSString *".

> - (NSString) enumToString: (Pet) pet
> error: syntax error before 'Pet'

Try the above with a typedef.

mobabo

unread,
Nov 16, 2008, 2:31:15 PM11/16/08
to
Ah, absolutely right. The second and hopefully last time that burns
me. Thanks.

0 new messages