Technical Knowledge

How can you obtain the common parent of two UIViews in a view hierarchy? Please provide your solution.

iOS Engineer

Meta

Google

Imgur

Venmo

Disney

LinkedIn

Did you come across this question in an interview?

Answers

Anonymous

4Strong
For the first UIView I would iterate up the chain of each UIView's parent property adding each parent to a Dictionary or Set. For the next UIView I would then follow the same process but I would be comparing against the existing Dictionary or Set. The first parent that I find matching in the dictionary or set I know is the lowest common parent of the two UIViews

Anonymous

3.2Strong
if we have 2 views, I would create a set of view, going up in the heirchery using view.superview, If I find that both the parent views are same or if any of the parent view was already in the set, then I have the answer.

  • How can you obtain the common parent of two UIViews in a view hierarchy? Please provide your solution.
  • Could you explain how you would find the common parent of two UIViews in a view hierarchy? Please elaborate.
  • Share your approach to retrieving the common parent of two UIViews in a view hierarchy.
  • Can you outline the process you would follow to obtain the common parent of two UIViews in a view hierarchy?
  • Describe the steps you would take to determine the common parent of two UIViews in a view hierarchy.
  • Explain the algorithm you would use to find the common parent of two UIViews in a view hierarchy.
  • How would you go about obtaining the common parent of two UIViews in a view hierarchy? Provide your implementation details.
  • What method would you use to determine the shared superview for a pair of UIViews?
  • Describe how you would identify the closest common ancestor in a view hierarchy between two UIViews.
  • Can you outline the process to find the common parent view for two UIViews in a hierarchy?
  • How would you get the common parent of two UIViews in a view hierarchy.
Try Our AI Interviewer

Prepare for success with realistic, role-specific interview simulations.

Try AI Interview Now

Interview question asked to iOS Engineers interviewing at Instagram, Imgur, Airbnb and others: How can you obtain the common parent of two UIViews in a view hierarchy? Please provide your solution..