iOS / Objective-C - 如何检查枚举是否可用? [英] iOS/Objective-C - How to check if an enum is available?

查看:96
本文介绍了iOS / Objective-C - 如何检查枚举是否可用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试测试设备上运行的iOS版本中是否有特定的枚举。我正在使用以前版本的操作系统中没有的特定枚举。我已经知道如何使用respondsToSelector测试方法可用性,如下所示:

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?

推荐答案

我认为你不能直接检查枚举可用性,但是你实际上并不需要它。

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

只需检查一个你知道在同一个iOS版本上可用的选择器可用性,你知道它有你需要的枚举。换句话说,检查一下与枚举同时添加到iOS的选择器。

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.

这篇关于iOS / Objective-C - 如何检查枚举是否可用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆