Re: How do I disable this warning: "local declaration of 'varname' hides instance variable"
Re: How do I disable this warning: "local declaration of 'varname' hides instance variable"
- Subject: Re: How do I disable this warning: "local declaration of 'varname' hides instance variable"
- From: Dave Hersey <email@hidden>
- Date: Mon, 24 Mar 2008 00:49:57 -0400
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@hidden> 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--
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden