I am having trouble finding a way to return an array of instances of a particular type of dynamic class at runtime in Swift.
I successfully compiled and tested this version, which returns a single instance of the class:
class Generic {
class func all() -> Self {
return self.init()
}
required init() {
}
}
class A: Generic {
}
let a = A.all()
The task here is to get compilation in order to allow functions to be allprototyped as follows: class func all() -> [Self](i.e. return an array of instances, working with subclasses, without casting ).
class Generic {
class func all() -> [Self] {
return [self.init()]
}
required init() {
}
}
class A: Generic {
}
let a = A.all()
Generic class func all() -> [Generic], A as!. begin A Self, "" . , , , ?
, , .
. , AnyObject. , , .
class Generic {
class func all() -> [AnyObject] {
return [self.init()]
}
required init() {
}
}
class A: Generic {
}
let a = A.all() as! [A]
!
PS: / . "Swifty" , , . , , , , , .