【问题标题】:Using enums in method arguments in Objective-C在 Objective-C 的方法参数中使用枚举
【发布时间】:2014-09-22 11:04:10
【问题描述】:

我有一个头文件ApiManager.h,我在其中定义了一个枚举:

typedef enum ApiEndpoint {
    // some values
} ApiEndpoint;

在该文件中,我有一个将这些值之一作为参数的方法:

- (NSString *) getPathForEndpoint: (ApiEndpoint) endpoint;

这对 XCode 来说似乎很好。然而,在另一个文件ApiManagerDelegate.h 中,我有以下定义:

- (void) requestToEndpoint: (ApiEndpoint) endpoint succeeded: (id) responseObject;
- (void) requestToEndpoint: (ApiEndpoint) endpoint failed: (NSError *) error;

XCode 将两个 ApiEndpoint 参数标记为错误 expected a type。我已经导入了ApiManager.h,所以ApiEndpoint 确实出现在完成列表中,但由于某种原因,XCode 无法识别它。

我做错了什么?

【问题讨论】:

  • 我建议使用 typedef NS_ENUM(NSInteger, UITableViewCellStyle) 宏来定义您的枚举。

标签: objective-c xcode enums


【解决方案1】:

看起来循环依赖是问题所在,正如@trojanfoe 所指出的,他神秘地删除了他的答案。

typedef 移动到单独的文件ApiEndpoint.h 解决了这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多