ryanrhee
ryanrhee

Reputation: 2571

Explicitly refer to member variable to remove "Local declaration of ... hides instance variable" warning

I have this segment of code:

- (void)setTableView:(UITableView *)tableView {
    tableView = tableView;
}

Now, I understand why I'm getting the warning. But shouldn't this fix it?

- (void)setTableView:(UITableView *)tableView {
    self->tableView = tableView;
}

I'm aware I can change the argument name or the ivar name, but i don't want to. In C++ for example, one can use this->foo = foo, and java one can use this.foo = foo. Python can use self.foo = foo. What's the equivalent in objc? (And no, I don't want to use @property's.)

Upvotes: 0

Views: 79

Answers (1)

Jonathan Grynspan
Jonathan Grynspan

Reputation: 43472

The problem is that the parameter's name is shadowing the ivar's name even on the right-hand side of the assignment. While you and I know you mean to assign the parameter's value to the ivar, the compiler can't be certain, so it warns you.

Change the name of the parameter and the warning will go away.

Upvotes: 1

Related Questions