简体   繁体   中英

Using enums in method arguments in Objective-C

I have a header file ApiManager.h in which I define an enum:

typedef enum ApiEndpoint {
    // some values
} ApiEndpoint;

In that file, I have a method that takes one of these values as an argument:

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

And that seems to be fine for XCode. In another file, however, ApiManagerDelegate.h , I have the following definitions:

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

And XCode flags both of the ApiEndpoint arguments with the error expected a type . I have imported ApiManager.h so ApiEndpoint does show up in the completions list, but for some reason XCode isn't recognising it.

What am I doing wrong?

It looks like cyclic dependencies were the problem, as pointed out by @trojanfoe who has mysteriously deleted his answer.

Moving the typedef to a separate file ApiEndpoint.h solved the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM