I've written a function that iterates through the superviews of a given UIView to obtain a reference to a specific UIView subclass if present (in this instance, UITableView). This works fine using imperative style but it does seem to be a problem that would lend itself very well to 'Railway Oriented Programming'. As I'm still getting my head around functional, is anyone able to suggest a more elegant functional version of this function?
func findTableView(var view: UIView) -> UITableView? {
var table: UITableView? = nil
while table == nil {
guard let superView = view.superview else { return nil }
view = superView
table = view as? UITableView
}
return table
}