I'm trying to define a Swift class that has a recursive function that returns the names of all the variables in the class. It works for printing it's variables, but when I use this I'll be using it as a base class for my models, and I may have multiple layers of inheritance. I want the method to return an array of all variable names on the current instance, as well as the names of any variables on any super classes, until we reach the base Cool
class.
class Cool:NSObject {
func doStuff() -> [String] {
var values = [String]()
let mirrorTypes = reflect(self)
for i 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 is in:
if let superCool = super as! Cool while name == "super" {
It causes an Expected '.' or '[' after super
compiler error.