Created
May 26, 2016 16:24
-
-
Save lightsprint09/32e7e0c4e384e5cfa684896e78d12e18 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment