Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extension Array {
- /**
- Hacky way to may a Array with Type Elemnet to an arry with Supertype T. T must be Supertype of Array.Element
- - returns: array of type T
- */
- func mapType<T>() -> Array<T> {
- let mappedCategorys: Array<T> = self.map { return $0 as! T }
- return mappedCategorys
- }
- }
- //Usage
- protocol Foo {}
- struct Bar: Foo {}
- let listOfBar = [Bar(), Bar()]
- let listOfFoo: Array<Foo> = listOfBar.mapType()
Add Comment
Please, Sign In to add comment