Using the result of an assignment as a condition without parentheses

ios, iphone, objective-c

Solution

This is probably not an error as you said, it's a warning.

The compiler is warning you that you should surround assignments within parentheses when it is within a conditional to avoid the ol' assignment-when-you-mean-comparison mistake.

To get past this rather pedantic compiler warning, you can simply surround the assignment within another pair of parentheses:

while((title = va_arg(args,NSString*))) {
//...
}

Problem

I have this inside a custom UIActionSheet class ``` if (otherButtonTitles != nil) { [self addButtonWithTitle:otherButtonTitles]; va_list args; va_start(args, otherButtonTitles); NSString * title = nil; while(title = va_arg(args,NSString*)) { // error here [self addButtonWithTitle:title]; } va_end(args); } ``` I have this error ! using the result of an assignment as a condition without parentheses pointing to this line ``` while(title = va_arg(args,NSString*)) { ``` why is that? thanks.

Original source