objective-c - 使用typedef枚举时,返回类型枚举EnumName返回枚举成员时会产生编译器错误

标签 objective-c enums compiler-errors typedef return-type

我有一个枚举

typedef enum {
    kOne,
    kTwo,
    kThree,
    kFour
} Enums;

而且,在我的.h文件中
- (enum Enums)getEnum;

在我的.m文件中
- (enum Enums) getEnum {
    return kOne;
}

但是,我得到了错误

Returning 'int' from a function with incompatible result type 'enum Enums'



我要返回一个枚举,所以我不确定错误是什么。

最佳答案

您的方法签名应为:

- (Enums)getEnum;

关于objective-c - 使用typedef枚举时,返回类型枚举EnumName返回枚举成员时会产生编译器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23255480/

相关文章:

ios - 从另一个类添加 View 作为 presentViewController 导致 UIEvents 不工作

java - 如何使用 Hibernate/JPA 将 JAVA 枚举映射到 Postgresql 枚举?

Java枚举按数字范围搜索

c# - 无法隐式转换类型'bool ?' to bool on "whereapprovmentState=true"

c++ - “SerialStream”没有命名类型

iphone - capitalizedString 将连字符后的单词大写?

objective-c - iOS TextView 不更新

mysql - 在 MySQL 中使用字符串枚举 - 性能问题

error-handling - 配置: error: C++ compiler cannot create executables See `config.log' for more details

iphone - 从相机胶卷加载的图片在纵向模式下过于拉伸(stretch)