Typedef update / extension defined in the Objective-C protocol in the class corresponding to the protocol

I have an Objective-C protocol:

typedef enum {
    ViewStateNone
} ViewState;

@protocol ViewStateable

- (void)initViewState:(ViewState)viewState;
- (void)setViewState:(ViewState)viewState;

@end

I use this protocol in the following class:

#import "ViewStateable.h"

typedef enum {
    ViewStateNone,
    ViewStateSummary,
    ViewStateContact,
    ViewStateLocation
} ViewState;

@interface ViewController : UIViewController <ViewStateable> {

}

@end

I will not go too far into the specification of my application, but what I am doing here is an typedefenumeration in the protocol so that the protocol methods can accept an input value of this type.

Then I hoped to update or extend this typedef in classes that conform to this protocol so that each class can have its own view states. However, I encountered two of the following errors:

  • Redeclaration of enumerator 'ViewStateNone'
  • Conflicting types for 'ViewState'

I am ashamed to admit that my knowledge of C (namely typedefs) is not extensive, and here is what I am trying to do here, firstly, perhaps, and secondly, reasonably?

Greetings from friends.

+5
2

. - , typedefs . (, , .) , (. ).


typedef type newtype;

()

#define newtype type;

enum {
  ViewStateNone
};

#define ViewStateNone 1

, typedefs , , .

; a typedef enum {} type; , , , , .

; , , . .

MyViewState, , NSInteger.


: . , - .

+6

, , , , , . ​​ typedef.

, , . , . , , , , . int , , , - NSString. , , .

+1

All Articles