codereviewanskquestions
codereviewanskquestions

Reputation: 13978

Objective C, A Question about return type of a method in a protocol

I have Type.h file looks like

typedef enum MessageType{
    msgTypeOne,
    msgTypetwo,
            .
            .
            .   
}

And I defined a protocol and a method in the protocol is trying to return the MessageType.. It looks like this

#import <UIKit/UIKit.h>
#import "Type.h"

@protocol Message

- (int) getId;
- (MessageType) getType;
- (int) getSize;
- (NSData *) toBytes;
- (void) fromBytes:(NSData *)data;

@end

Then I am getting an error saying "No type or storage class may be specified here before protocol"

Any ideas? How I can fix this?

Thanks in advance...

Upvotes: 1

Views: 1179

Answers (2)

BoltClock
BoltClock

Reputation: 723388

You need to typedef your enum to MessageType. Currently you are typedefing an enum MessageType to nothing.

Change your enum code to this, placing MessageType after the closing brace:

typedef enum {
    msgTypeOne,
    msgTypetwo,
    // ... 
} MessageType;

This typedefs an anonymous enum to the user-defined type MessageType. Your protocol should now compile correctly.

Upvotes: 4

Robin
Robin

Reputation: 10011

@Chayong Lee you need to define the protocol at the end of the class something like this

#import <UIKit/UIKit.h>
interface something : NSObject
{
}

@end
@protocol some

@end

and if you are using that protocol in the interface then you need to do something like this

#import <UIKit/UIKit.h>

@protocol some;

interface something : NSObject
{
}

@end
@protocol some

@end

Upvotes: 0

Related Questions