Reputation: 933
- we can bind data to the
UITableViewCell
like below indidSet
method.
class NameCell: UITableViewCell {
@IBOutlet weak var nameLabel: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
selectionStyle = .none
}
var name: String! {
didSet {
nameLabel.text = name
}
}
}
- Or we can bind the data using a function like below.
class NameCell: UITableViewCell {
@IBOutlet weak var nameLabel: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
selectionStyle = .none
}
func bindName(name: String) {
nameLabel.text = name
}
}
What is the difference between these two approaches when it comes to performance and reliability of the app with large chunk of data
Upvotes: -1
Views: 115
Reputation: 2315
This varies from developer to developer. I prefer the first one if the code structures in didset
is too small. But if you make some calculations and decisions then the second one is better to me. It actually depends on you, so there is no specific answer.
Upvotes: 1