Guest User

Untitled

a guest
May 26th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. extension Array {
  2. /**
  3. Hacky way to may a Array with Type Elemnet to an arry with Supertype T. T must be Supertype of Array.Element
  4.  
  5. - returns: array of type T
  6. */
  7. func mapType<T>() -> Array<T> {
  8. let mappedCategorys: Array<T> = self.map { return $0 as! T }
  9.  
  10. return mappedCategorys
  11. }
  12. }
  13.  
  14. //Usage
  15. protocol Foo {}
  16. struct Bar: Foo {}
  17. let listOfBar = [Bar(), Bar()]
  18. let listOfFoo: Array<Foo> = listOfBar.mapType()
Add Comment
Please, Sign In to add comment