Using @property and weak properties in Objective-C

I have a specific question, and I could not find an answer to it.

I have a storyboard that has some looks. Some of the species have exits. I understand that I should declare my access points weak parameters, but I do not know if I should declare recipients and setters (using @property and synhesize).

1 - __weak IBOutlet UITableView *table;
2 - @property(nonatomic, weak) UITableView *table; 

If I just declare (1), I can just make a β€œtable” on the view controller.

If I declare (1) and (2), I can do self.table.

Who cares? What is the best approach?

+3
source share
4 answers

(1) - . (2) . , . , API , .

, . , , self, weakSelf. , .

(.), , , (->).

, :

[_tableView reloadData];

[self->_tableView reloadData];

, -> nil .

+4

"" , , @synthesize .

0

- , - . , , , iVar, _varName. _varName self.varName. , , getter.

0

As a rule, there is no reason to declare withdrawal as a strong property, implying a right of ownership. Most of the views belong to their observations.

@property (weak) IBOutlet UITableView *table;

Then you process like any other property

@synthesize table = _table;
- (void)someMethod
{
     [self.table doSomething ....]
}

See also Managing Object Life Time from Nib Files

-1
source

All Articles