Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Annoying warning: Integer constant not in the range of enumerated type 'UIViewAnimationOptions'

When writing code like the following in XCode 5 using clang set to C11/C++11:

[UIView animateWithDuration:0.5
    delay:0
    options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat
    animations:^{
        self.imgCheckIn.backgroundColor = [UIColor redColor];
    }
    completion:nil];

The options field generates the following warning:

integer constant not in range of enumerated type 'UIViewAnimationOptions' (aka 'enum UIViewAnimationOptions') [-Wassign-enum]

The problem seems to be that the method takes a UIViewAnimationOptions type, which is just an enum of NSUInteger. However, OR'ing values together creates a value that isn't explicitly in the enum, so it complains.

In general this seems to be a nice kind of warning to have so I'd like to keep it. Am I doing something wrong?

like image 293
Tim Avatar asked Nov 19 '13 19:11

Tim


1 Answers

You are doing nothing wrong. As you already noticed, the compiler complains because the value is none of the values defined in the enumeration. (The compiler flag -Weverything implies this check.)

You can suppress the warning either by an explicit cast:

options:(UIViewAnimationOptions)(UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat) 

or with a #pragma:

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wassign-enum"
[UIView animateWithDuration:0.5
                      delay:0
                    options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat
                 animations:^{
                     self.imgCheckIn.backgroundColor = [UIColor redColor];
                 }
                 completion:nil];
#pragma clang diagnostic pop
like image 125
Martin R Avatar answered Oct 29 '22 22:10

Martin R