dimanche 18 février 2018

Reflection: get static vars of class in Swift?

Given a simple class like:

class Foo {
    static var can: String? { didSet { 5+4 } }
    static let haz: String
}

How do I implement a method within Foo that enumerates over can and haz; without explicitly writing them out again? - E.g.: so I can print("key: '\(key\)' has value: '\(value)'")


BTW: Noticed this: How to loop over struct properties in Swift?; but couldn't get it to work for static.





Aucun commentaire:

Enregistrer un commentaire