Skip to content

Instantly share code, notes, and snippets.

@dnedrow
Forked from danielt1263/UIViewAdditions.swift
Created September 22, 2018 12:43
Show Gist options
  • Select an option

  • Save dnedrow/fc57dc51771bdf348cfd970e7f786dab to your computer and use it in GitHub Desktop.

Select an option

Save dnedrow/fc57dc51771bdf348cfd970e7f786dab to your computer and use it in GitHub Desktop.
//
// UIViewAdditions.swift
//
// Created by Daniel Tartaglia on 04/15/15.
// Copyright © 2016. MIT License.
//
import UIKit
extension UIView {
func findDeepChildSatisfyingCriteria(criteria: (_ view: UIView) -> Bool) -> UIView? {
var queue: [UIView] = []
queue.append(self)
while !queue.isEmpty {
let view = queue[0]
queue = Array(queue.dropFirst())
if criteria(view) {
return view
}
else {
for subview in view.subviews {
queue.append(subview)
}
}
}
return nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment