Skip to content

Instantly share code, notes, and snippets.

@djtech42
Last active August 29, 2015 14:24
Show Gist options
  • Save djtech42/f8784bb7268ae6d0bfc1 to your computer and use it in GitHub Desktop.
Save djtech42/f8784bb7268ae6d0bfc1 to your computer and use it in GitHub Desktop.
Process subviews of a specific type recursively
/**
Perform function on all views that match type specified by function parameter.
*/
func iterateThroughViewsIn<SpecificViewType>(view: UIView, function: SpecificViewType -> Void) {
for subview in view.subviews {
if let viewOfSpecificType = subview as? SpecificViewType {
function(viewOfSpecificType)
}
iterateThroughViewsIn(subview, function: function)
}
}
iterateThroughViewsIn(view, function: { (scrollView: UIScrollView) in
scrollView.scrollEnabled = false
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment