Skip navigation.
 
mlRe: How do I disable this warning: "local declaration of 'varname' hides instance variable"
FROM : charlie
DATE : Mon Mar 24 06:04:41 2008

It's not about extra characters I have to type.  It just looks fugly to
me.  It always has.  And I'm not saying this solution is perfect.  It's
ugly too.  Just less ugly to my eyes.  In fact, I may end up hating it
after this project.. but I want to at least try it once and see how I
feel about it afterward.

"aController" is exactly what I'm tring to avoid, by the way.  I want
to call it "controller", nothing less, nothing more.  Same goes for the
instance variable.

This is why I didn't want to reveal **why** I want to suppress this
warning.  Because everyone feels compelled to pitch in their 2 cents on
this tangent subject which has already been explored and closed on my
end.

I could care less what anyone else thinks about this decision.

I simply want to know how to suppress the warning.

That's it.

- Chuck








On March 24, 2008, Dave Hersey wrote:

>> For example, the above could be rewritten as:
>>
>> - (void)setController:(id)newController {
>>    if (!controller) return;
>>    controller = [newController retain];

>
> I think the if (!controller) check was for the passed-in value, not 
> the instance variable, but there lies the confusion about using the 
> same name for instance variables and parameters like this.
>
> I can't think of any reason NOT to take the time to type a few more 
> characters in that parameter name to make things clear. You've already 
> spent much more time trying to work around the warning than fixing it 
> like Sherm says.
>
> Also, I'm guessing that this method is only called once, because 
> otherwise your memory management is hosed. I'd normally do these 
> retaining setter methods like this, just out of habit:
>
> - (void) setController: (id) aController
> {
>     id    tempObject = m_controller;     // m_controller is the instance var.
>     m_controller = [aController retain];    // retain before releasing the 
> old value in case m_controller
>     [tempObject release];                // and aController are the same.
> }
>
> I realize it's a controller in this case so you're probably only 
> calling it once, but it's very little extra typing to write it safe. 
> Finally, you don't need to check for nil in your code if you're only 
> calling it once, because [nil retain] == nil.
>
> So, you could write your code like:
>

>> - (void)setController:(id)newController {
>>    controller = [newController retain];
>> }

>
>
> - d
>
> On Mar 24, 2008, at 12:18 AM, Sherm Pendley wrote:

>> On Sun, Mar 23, 2008 at 11:59 PM, charlie <<email_removed>> wrote:
>> ...
>> - (void)setController:(id)controller
>> {
>> if (!controller)
>> {
>>  return;
>> }
>> self->controller = [controller retain];
>> }
>>

>>> ...

>> So, the question stands.... How do I suppress the warning.
>>
>>
>> You suppress the warning by fixing the problem it's warning you 
>> about. Yes,
>> it's just that simple.
>>
>> For example, the above could be rewritten as:
>>
>> - (void)setController:(id)newController {
>>    if (!controller) return;
>>    controller = [newController retain];
>> }
>>
>> sherm--
>>

>