Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //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!)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement