Saturday, July 16, 2011

Sometimes, don't listen to the compiler

Was testing this "colour picker" code from http://www.skylarcantu.com/blog/2009/08/14/custom-uialertview-color-chooser/. As below, compiler gave me warning about "Using the result of an assignment as a condition without parenthesis". The suggestion is "use '==' to turn this assignment into an equality comparison" and "Place parentheses around the assignment to silence this warning".

I followed that and then noticed....wait...that's not right!

The author was actually combining the following 2 lines:


    self = [super initWithFrame];
    if (self) {
        

into 1 line:


    if (self=[super initWithFrame:frame]) {


If I use "==" instead of "=" as suggested, that would be wrong! So I guess sometimes we shouldn't listen to the compiler...

0 comments:

Post a Comment