Last active
December 3, 2015 17:01
-
-
Save Struki84/8b2040658e3b6585d8a7 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
//Consider the scenario | |
class Foo { | |
var foBarVar: String? | |
init() { | |
foBarVar = "Test" | |
} | |
func someFunction() { | |
} | |
} | |
class Bar { | |
var barFoVar: String? | |
init() { | |
barFoVar = "Test" | |
} | |
func barFunction() { | |
} | |
} | |
//Create array with "Foo" and "Bar" classes | |
var array: [AnyClass] = [] | |
array.append(Foo) | |
array.append(Bar) | |
//The question is, How to instantiate the clases from the array? | |
//Obviously this is not correct, just a sketch of the concept | |
for className in array { | |
let objectFromClass = className() | |
print(objectFromClass.foBarVar!) | |
} | |
kviksilver
commented
Dec 3, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment