My friend was asked to implement dequeueReusableCell(withIdentifier:) in swift for iOS Engineer role at Facebook.
Question
Imagine that you work an Apple, and suddenly the implementation code is lost. What you have to do is to implement the code for dequeueReusableCell(withIdentifier:). How would you implement that function?
class UItableView: UIScrollView {
func dequeueReusableCell(withIdentifier identifier: String) -> UITableViewCell? {
}
}
My Implementation:
class UItableView: UIScrollView {
let cells = [UITableViewCell]()
func dequeueReusableCell(withIdentifier identifier: String) -> UITableViewCell? {
return cells.filter { $0.identifier == identifier }.first
}
}
I am not sure how correct it is.
I think dictionary that store cells with there index would be a better approach.
Could anyone please comment how to write this function?