The filter
function using the is
operator can filter items of a specific class.
let myViews = view.subviews.filter{$0 is MyButtonClass}
MyButtonClass
is the custom class to be filtered for.
To filter and cast the view to the custom type use compactMap
let myViews = view.subviews.compactMap{$0 as? MyButtonClass}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…