Mark Struzinski
Mark Struzinski

Reputation: 33471

iOS/Objective-C - How to check if an enum is available?

I'm trying to test if a specific enum is available in the version of iOS running on a device. I am using a specific enum that is not available in previous versions of the OS. I already know how to test for method availability by using respondsToSelector like this:

if ([self respondsToSelector:@selector(method:)]) {

}

Is there a similar test for enums? If not, how can I test for it?

Upvotes: 6

Views: 2635

Answers (2)

Praveen Castelino
Praveen Castelino

Reputation: 69

There is no method to check for the availability of the enum at the runtime. Best method would be to check for iOS version or check for the feature that you would want to enable or provide depending on the iOS version. If you can tell us the feature, I'm sure someone out here will surely be able to help you out.

Upvotes: 1

sergio
sergio

Reputation: 69027

I don't think that you can directly check for an enum availability, but you don't actually need it.

Simply check for one selector availability that you know is available on the same iOS version that you know has got the enum you need. In other words, check for some selector that was added to iOS at the same time as the enum.

It is not actually the same, but I think it does reasonably what you need. If the selector you check for does use that enum, you are pretty close to the perfect solution.

Upvotes: 3

Related Questions