我有这段代码:

#import <Foundation/Foundation.h>
@class Completions;

typedef enum inputSource { KEY_TYPE = 0, WORD_SELECTION = 1, MOVEMENT = 3, BACKSPACE = 4 } InputSource;
...


由于某种原因,我在行上收到错误消息:

`typedef enum inputSource { KEY_TYPE = 0, WORD_SELECTION = 1, MOVEMENT = 3, BACKSPACE = 4 } InputSource`;


这里有什么问题?

最佳答案

使用:typedef enum { KEY_TYPE = 0, WORD_SELECTION = 1, MOVEMENT = 3, BACKSPACE = 4 } InputSource;

您不需要inputSource

或更妙的是,使用新的Objective-C样式:

typedef NS_ENUM(NSInteger, InputSource) {
    KEY_TYPE = 0,
    WORD_SELECTION = 1,
    MOVEMENT = 3,
    BACKSPACE = 4
};

09-25 17:21