Swift subclassing, recursion, and super casting -
i'm trying define swift class has recursive function returns names of variables in class. works printing it's variables, when use i'll using base class models, , may have multiple layers of inheritance. want method return array of variable names on current instance, names of variables on super classes, until reach base cool
class.
class cool:nsobject { func dostuff() -> [string] { var values = [string]() let mirrortypes = reflect(self) in 0 ..< mirrortypes.count { let (name, type) = mirrortypes[i] if let supercool = super as! cool while name == "super" { values += supercool.dostuff() } } return values } }
the problem in:
if let supercool = super as! cool while name == "super" {
it causes expected '.' or '[' after super
compiler error.
Comments
Post a Comment