-
-
Save dnedrow/fc57dc51771bdf348cfd970e7f786dab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // 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