Skip to content

Instantly share code, notes, and snippets.

@JohannMG
Created May 2, 2017 00:02
Show Gist options
  • Save JohannMG/b0c398e0e65aee24f8c40bd9af0e6d52 to your computer and use it in GitHub Desktop.
Save JohannMG/b0c398e0e65aee24f8c40bd9af0e6d52 to your computer and use it in GitHub Desktop.
I write this so much. Saved.
import Foundation
extension Collection {
func onlyType<T>(_ type: T.Type) -> [T] {
return self.filter{ $0 is T }.map{ $0 as! T }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment