Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. //Consider the scenario
  2.  
  3. class Foo {
  4.  
  5. var foBarVar: String?
  6.  
  7. init() {
  8. foBarVar = "Test"
  9. }
  10.  
  11. func someFunction() {
  12. }
  13. }
  14.  
  15. class Bar {
  16.  
  17. var barFoVar: String?
  18.  
  19. init() {
  20. barFoVar = "Test"
  21. }
  22.  
  23. func barFunction() {
  24. }
  25. }
  26.  
  27. //Create array with "Foo" and "Bar" classes
  28. var array: [AnyClass] = []
  29. array.append(Foo)
  30. array.append(Bar)
  31.  
  32. //The question is, How to instantiate the clases from the array?
  33. //Obviously this is not correct, just a sketch of the concept
  34. for className in array {
  35. let objectFromClass = className()
  36. print(objectFromClass.foBarVar!)
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement