Last active
November 24, 2017 13:19
-
-
Save xNekOIx/f8f0ecd8482d68b90c9773459a8d493e to your computer and use it in GitHub Desktop.
Recursive view search for condition
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
typedef BOOL(^SCConditionBlock)(UIView *subview); | |
UIView * SCFindSubviewForCondition(UIView *view, SCConditionBlock conditionBlock); | |
UIView * SCFindSubviewForCondition(UIView *view, SCConditionBlock conditionBlock) { | |
NSCParameterAssert(view != nil); | |
if (conditionBlock(view)) { | |
return view; | |
} | |
let subviews = [view subviews]; | |
__block UIView *satisfiedView = nil; | |
[subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { | |
satisfiedView = SCFindSubviewForCondition(obj, conditionBlock); | |
if (satisfiedView) { | |
*stop = YES; | |
} | |
}]; | |
return satisfiedView; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment