Pass in a type to a generic Swift extension, or ideally infer it
Say you have class Fancy:UIView you want to find all sibling Fancy views. No problem ... for v:UIView in superview!.subviews { if let f = v as? Fancy { f.hungry = false } } So, try an extension, public extension UIView { internal func fancySiblings()->([Fancy]) { return (self.superview! .subviews .filter { $0 != self } .flatMap { $0 as? Fancy } ) } } Awesome, you can now for f:Fancy in self.fancySiblings() { f.hungry = false } Fantastic. But, How to generalize that extension to work with any UIView subtype? Ideally, can the extension infer the type , even? As well as taking a type? So,