warning on typedef enum when converting app to 64-bit

64-bit, enums, ios, objective-c

Solution

According to apple docs about 64-bit changes.

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

To solve this, create enumeration with type as below syntax.

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

or

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

Problem

I am converting my iOS app to 64-bit. I have the latest Xcode 5.1 (beta 4) installed. When I compiled the app, I received over 100 warnings and most of them are pretty easy to fix. However, I have a warning on the following code: ``` + (CommentResponseStatus)commentReponseStatusCodeWithStatusString:(NSString *)_status { NSArray *commentStatusString = [NSArray arrayWithObjects:@"success", @"needConfirmation", @"stopped", nil]; return [commentStatusString indexOfObject:_status]; } ``` Where `CommentResponseStatus` is declared as: ``` typedef enum { success, needConfirmation, stopped } CommentResponseStatus; ``` I have a warning "Implicit conversion loses integer precision: '`NSUInteger`' (aka '`unsigned long`') to '`CommentResponseStatus`'" The warning is on the line `return [commentStatusString indexOfObject:_status];` In `NSArray` we have `- (NSUInteger)indexOfObject:(id)anObject;` I am confused about this warning and don't know for now how to fix it. Any quick help would be appreciated.

Original source

Related problems