Last active
December 4, 2018 21:36
-
-
Save danielt1263/c6d6c217e50fdfb5d00cc1e6cc00c584 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 findDeepChildSatisfying(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