ios - 将应用程序转换为 64 位时对 typedef 枚举发出警告

标签 ios objective-c enums 64-bit

我正在将我的 iOS 应用程序转换为 64 位。我安装了最新的 Xcode 5.1 (beta 4)。

当我编译该应用程序时,我收到了 100 多个警告,其中大部分都非常容易修复。但是,我对以下代码发出警告:

+ (CommentResponseStatus)commentReponseStatusCodeWithStatusString:(NSString *)_status
{
    NSArray *commentStatusString = [NSArray arrayWithObjects:@"success", @"needConfirmation", @"stopped", nil];

    return [commentStatusString indexOfObject:_status];
}

CommentResponseStatus 声明为:

typedef enum {
    success,
    needConfirmation,
    stopped
} CommentResponseStatus;

我有一个警告“隐式转换失去整数精度:'NSUInteger'(又名'unsigned long')到'CommentResponseStatus'”

警告在行 return [commentStatusString indexOfObject:_status];

NSArray 中我们有 - (NSUInteger)indexOfObject:(id)anObject;

我对这个警告感到困惑,现在不知道如何解决它。任何快速帮助将不胜感激。

最佳答案

根据 apple docs关于 64 位更改。

Enumerations Are Also Typed : In the LLVM compiler, enumerated types can define the size of the enumeration. This means that some enumerated types may also have a size that is larger than you expect. The solution, as in all the other cases, is to make no assumptions about a data type’s size. Instead, assign any enumerated values to a variable with the proper data type

要解决此问题,请按以下语法创建带类型的枚举

typedef NS_ENUM(NSUInteger, CommentResponseStatus) {
    success,
    needConfirmation,
    stopped
};

typedef enum CommentResponseStatus : NSUInteger {
    success,
    needConfirmation,
    stopped
} CommentResponseStatus;

关于ios - 将应用程序转换为 64 位时对 typedef 枚举发出警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21431696/

相关文章:

c# - 当我知道我有一组有限的不同选项时使用枚举或一组类?

ios - 从 iOS 上的两个 jpeg 加载 RGBA 图像 - OpenGL ES 2.0

ios - iOS 中的非典型左侧菜单(附有屏幕)

objective-c - 如何使用 route-me 创建透明层

ios - 如何检查相机是否打开以捕获图像或在 iOS 中录制视频?

c++ - 将 char 绑定(bind)到枚举类型

ruby - 在 ruby​​ 中交错两个枚举的最佳方法?

java - 尝试快速使用 CMYK 值

ios - 在 XCode 5 中包含一个包

ios - Codility 编程测试和 Objective-C 语法