Facebook | Phone | Implementing UIKit Code
Company: Meta (Facebook)
Role: e3
Interview Stage: Phone Screen
Location: unknown
Year: unknown
Original Post Content:
Hello, everyone. I got this question from a Facebook Interview. I couldn't resolve at that moment and I offer my quick solution on how I imagine that it works.
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 solution
As it was a question that was to be answered quickly what I had answered was:
Assuming there's an array that stores all the cells in the UITableView, I'd use it to find that cell:
class UItableView: UIScrollView {
let cells = [UITableViewCell]()
func dequeueReusableCell(withIdentifier identifier: String) -> UITableViewCell? {
return cells.filter { $0.identifier == identifier }.first
}
}
If there is a better answer, please post it in the comments. Thanks in advance.