Swift: Get all subviews of a specific type and add to an array
问题 I have a custom class of buttons in a UIView that I'd like to add to an array so that they're easily accessible. Is there a way to get all subviews of a specific class and add it to an array in Swift? 回答1: 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. 回答2: Here you go extension UIView { /** This is the function to get subViews of a view of a