Guest User

Untitled

a guest
Jun 24th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. var list:[Any] = ["A Random String", 12, 5.2, CGPoint.zero]
  2.  
  3. // Since the list contains elements of type Any, we can append anything into it.
  4. list.append(UIColor.red)
  5.  
  6. // Since type is Any, to use any of the elements we need to type check them:
  7. list.forEach { (element) in
  8. switch element {
  9. case is String:
  10. print("String detected: \(element)")
  11. case is Int:
  12. print("Int detected: \(element)")
  13. case is Double:
  14. print("Double detected: \(element)")
  15. case let point as CGPoint:
  16. print("frame detected: x:\(point.x) y:\(point.y)")
  17. default:
  18. print("Default: \(element)") /* will print the UIColor
  19. as this doesn't fall into any case */
  20. }
  21. }
Add Comment
Please, Sign In to add comment