Is there a way to achieve this in Swift 2.1
class Apple
{
}
class Fruit
{
let apples = [Apple]();
}
let fruit = Fruit();
let appleType: AnyClass = Apple.self;
let applesType: Any = fruit.apples.self.dynamicType;
let properties = Mirror(reflecting: fruit).children;
for property in properties
{
let magicalApples = property.value;
let array = Array<appleType>(); // creating array of Apple from type
let apples = magicalApples as! Array<appleType> // typecasting to array of Apple from type
let moreApples = magicalApples as! applesType // typecasting to [Apple] from type
let anyApples = magicalApples as! Array<AnyObject> // error SIGABRT, is this a bug?
}
Commented objectives throws error, "Use of undeclared type".
My objective is to know if appleType
, type stored in a var
, can be used as a Type