Add extensions to help finding private subviews

This commit is contained in:
Pete Schaffner
2024-02-07 11:10:43 +01:00
parent acbc6f77e8
commit e00197c1bd
3 changed files with 41 additions and 7 deletions

View File

@@ -0,0 +1,29 @@
import AppKit
extension NSView {
func firstSubview(withClassName name: String) -> NSView? {
for subview in subviews {
if String(describing: type(of: subview)) == name {
return subview
} else if let found = subview.firstSubview(withClassName: name) {
return found
}
}
return nil
}
func subviews(withClassName name: String) -> [NSView] {
var result = [NSView]()
for subview in subviews {
if String(describing: type(of: subview)) == name {
result.append(subview)
}
result += subview.subviews(withClassName: name)
}
return result
}
}