When I search for how to implement auto sizing cell in iOS I come across many examples (here here and here) with this mysterious code in - (CGFloat)heightForImageCellAtIndexPath:(NSIndexPath *)indexPath
static CommentedItemCell *sizingCell = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sizingCell = [self.tableView dequeueReusableCellWithIdentifier:kCellIdentifier];
});
But I can't find a reason behind this dispatch_once thing. I think its aim to save some memory, but why this style. Why not define property and lazy load it.
@property (nonatomic, strong) UITableViewCell sizingCell;
with
- (UITableViewCell)getSizingCell
{
if (_sizingCell) return _sizingCell;
_sizingCell = [self.tableView dequeueReusableCellWithIdentifier:kCellIdentifier];
return _sizingCell;
}
Want to know its just coding style or there is some benefit behind this dispatch_once implementation.