Sunday, 17 July 2011

Sometimes, don't listen to the compiler

Was testing this "colour picker" code from 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...

No comments:

Post a Comment