View hierarchy traversal
How would you write a function that starts at a root view and finds a view matching some condition (say, tag == 99 or a specific type)?
func findView(in root: UIView, where predicate: (UIView) -> Bool) -> UIView?How would you write a function that starts at a root view and finds a view matching some condition (say, tag == 99 or a specific type)?
func findView(in root: UIView, where predicate: (UIView) -> Bool) -> UIView?The view hierarchy is a tree, so pushing subviews onto a queue and testing the predicate as you go finds views closer to the root first. Consume the queue with a head index instead of removeFirst to stay O(n).
CS fundamentals and algorithmsShort answerAdvanced
You're given a specific UIView instance in an original view hierarchy, plus a copy of…
#view-hierarchy #bfs #dfs
UIKitShort answerAdvanced
Given several UIViews, how would you design a function that returns their nearest common…
#view-hierarchy #coding
CS fundamentals and algorithmsShort answerAdvanced
An image mask comes as an N×M grid where 1 is foreground and 0 is background. How would…
#bfs #dfs
UIKitShort answerBasics
You're writing a function that finds the nearest common parent of two UIViews. Which data…
#view-hierarchy