Jacksonkr Jacksonkr -3 years ago 137
iOS Question

ios obj.var = exp VS [obj var:exp]

Why/When do you use one over the other? I just ran into an issue where I got a warning using one and no warning when using the other.

example:

tableView.tableHeaderView = label; // worked
[tableView tableHeaderView:label]; // did not work - "instance method '-tableHeaderView:' not found (return type defaults to 'id')"


confused

Answer Source

setters are generally prefixed with set. Try this instead:

[tableView setTableHeaderView:label];

That is to say, this:

tableView.tableHeaderView = label;

is converted to:

[tableView setTableHeaderView:label];

automatically by the compiler when using dot notation.

When declaring an objc property, this convention is also applied to the declared property name for the setter (again, by default).

Getters don't use this convention, Their selectors are the same (by default) as the declared property name:

view = tableView.tableHeaderView;

is equal to:

view = [tableView tableHeaderView];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download