Objective-C 枚举最大(按位)限制(iPhone)
我有一个可以对定义为枚举的 Web 服务执行的调用列表,
typedef enum
{
ServiceCallGetDataA = 1 << 1;
ServiceCallGetDataB = 1 << 2;
ServiceCallGetDataC = 1 << 3;
ServiceCallGetDataD = 1 << 4;
..
} ServiceCall;
这是按位完成的,因此如果我调用我的服务管理器,我可以直接说
[ServiceManager getDataFor:( ServiceCallGetDataB | ServiceCallGetDataC )];
“哪个”然后为我提供 B 和 B 的数据。 C 服务。一切都很完美。
但我只能定义 32 个枚举,因为我正在开发的 iOS 平台是 32 位。
主要目标是保持 OR 运算完整,以便我使用 OR 运算获取/设置枚举。
有什么想法吗?
I have a list of calls i can do to a webservice defined in as an enumeration
typedef enum
{
ServiceCallGetDataA = 1 << 1;
ServiceCallGetDataB = 1 << 2;
ServiceCallGetDataC = 1 << 3;
ServiceCallGetDataD = 1 << 4;
..
} ServiceCall;
this is done bitwise so if i call my service manager i can just say
[ServiceManager getDataFor:( ServiceCallGetDataB | ServiceCallGetDataC )];
Which then gives me both data for the B & C service. It all works perfect.
but i can only define 32 enumerations because the iOS platform i'm developing for is 32bit.
The main goal is to keep the OR operation intact so that i get/set my enumeration using the OR operation.
any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您还可以尝试使用位向量而不是普通枚举。正如我发布这个问题时所建议的,您可以使用 CFMutableBitVector 来实现任意大小的位向量。
You can also try using bit vectors instead of a plain enumeration. As was suggested when I posted this question, you can use CFMutableBitVector to implement bit vectors of arbitrary sizes.
如果您需要更大的整数,可以使用
long long
类型,即使在 iOS 上也应该转换为 64 位整数。或者,您可以为每个服务使用带有常量字符串的
NSSet
变量。然后,您可以将它们组合起来,检查是否包含对象等。如果速度很关键,这可能不是一个选择,但如果这些函数不经常使用,这样您将拥有更大的灵活性。If you need bigger integers, you could use the type
long long
which even on iOS should translate into 64 bit integers.Alternatively you could use
NSSet
variables with constant strings for every service. You could then combine them, check if objects are contained etc. If speed is critical this might not be the option but if these functions are not used too often you would have a much greater flexibility this way.