Automatic property @synthesize


#1

When I don’t explicitly synthesize my properties for ‘id controller’ and ‘tableView’ (Adding pointer to cell subclass) I get this error:
"Property ‘tableView’ attempting to use instance variable ‘_tableView’ declared in super class ‘UITableViewCell’. If I manually synthesize tableView (@synthesize tableView;) this error disappears. I understand that this has something to do with using an existing _tableView instance variable?


#2

Okay, let me elaborate on this rather annoying subject.

In UITableViewCell.h there is a private instance variable declared as

When I don’t synthesize my tableView property because this is now default behavior in Xcode, a private instance variable is declared for me in HomepwnerItemCell.m:

This is also a private instance variable because this “automatic” synthesizing is the same as declaring an instance variable in the implementation section (private).

If I relay on default synthesizing I get an error telling me that I’m attempting to access the _tableView instance variable of the super class. I guess this is because the default getter would look something like this:

(UITableView *) tableView { return _tableView; //This is trying to access the private instance variable of the super class }
I don’t get it. I don’t understand why I get this error. The sub class is not supposed to inherit private instance variables of the super class. I guess there is something vital that I have overlooked but my brain is swollen from too much information in this chapter…


#3

You seem to be misunderstanding private instance variables. Subclasses still inherit then, just cannot access them unless it is via a property declaration. That’s why the error goes away when you synthesize.

Hope this helps.


#4

Thanks for the reply!
I must have misunderstood. Didn’t think the sub class inherited private instance variables. Thought that the sub class only inherited the accessor methods and not the instance variable. The UITableView *_tableView instance variable is not a property in the super class UITableViewCell so it doesn’t have a accessor method. That’s why I thought it was strange that the sub class attempted to access the instance variable of the super class… I’m still not really understanding this I think…