Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 692
Mark Struzinski Avatar asked Jun 24 '11 14:06

Mark Struzinski


2 Answers

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.

like image 138
sergio Avatar answered Oct 05 '22 11:10

sergio


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.

like image 36
Praveen Castelino Avatar answered Oct 05 '22 12:10

Praveen Castelino