Skip navigation.
 
mlRe: How do I disable this warning: "local declaration of 'varname' hides instance variable"
FROM : Dave Hersey
DATE : Mon Mar 24 05:49:57 2008

> 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--
>

Related mailsAuthorDate
mlRe: How do I disable this warning: "local declaration of 'varname' hides instance variable" charlie Mar 24, 04:59
mlRe: How do I disable this warning: "local declaration of 'varname' hides instance variable" j o a r Mar 24, 05:12
mlRe: How do I disable this warning: "local declaration of 'varname' hides instance variable" Sherm Pendley Mar 24, 05:18
mlRe: How do I disable this warning: "local declaration of 'varname' hides instance variable" Dave Hersey Mar 24, 05:49