Advertisement
Guest User

Untitled

a guest
Aug 31st, 2015
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. class A { }
  2.  
  3. let obj = A()
  4.  
  5. let array: [AnyObject] = [obj]
  6.  
  7. func isType<T, U>(x: T, type: U.Type) -> Bool {
  8. if let x = x as? U {
  9. return true
  10. } else {
  11. return false
  12. }
  13. }
  14.  
  15. // This works
  16. if let array = array as? [A] {
  17. println(true)
  18. }
  19.  
  20. // This works
  21. println(isType(obj, A.self))
  22.  
  23. // This doesn't
  24. println(isType(array, [A].self))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement