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: "charlie" <email@hidden>
- Date: Mon, 24 Mar 2008 05:46:45 +0000
"Right... Sorry, I misunderstood. So, you want to continue using your
flawed coding style, but not be warned about it? Got it."
Exactly. And.. I'm fully admitting that this is a goofy workaround,
but I want to try it nonetheless.
"If it's really important to you, send an incident to DTS and pay them
$195 for the answer. I suspect they'll tell you what we've told you."
I've worked with DTS before, and the vibe is very helpful. They would
probably remind me of the downside to doing it this way, but if there's
a way to disable that warning, they will tell me what it is.
"Otherwise, I'd ask on the Xcode list which is where this question now
belongs, since you're asking about compiler warnings and not Cocoa
development."
Good point. I think youre absolutely right.
This will give me a chance to think about how to better phrase my
question too.
- Chuck
On March 24, 2008, Dave Hersey wrote:
Right... Sorry, I misunderstood. So, you want to continue using your
flawed coding style, but not be warned about it? Got it.
If it's really important to you, send an incident to DTS and pay them
$195 for the answer. I suspect they'll tell you what we've told you.
Otherwise, I'd ask on the Xcode list which is where this question now
belongs, since you're asking about compiler warnings and not Cocoa
development.
Out of curiosity, why did you think that adding an underscore to both
the local and instance variable names, but still keeping them the same
would fix this problem?
- d
...who is up to 4 cents now.
On Mar 24, 2008, at 1:04 AM, charlie wrote:
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@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