Skip to content

Instantly share code, notes, and snippets.

@danielt1263
Last active December 4, 2018 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save danielt1263/c6d6c217e50fdfb5d00cc1e6cc00c584 to your computer and use it in GitHub Desktop.
Save danielt1263/c6d6c217e50fdfb5d00cc1e6cc00c584 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 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