dimanche 28 janvier 2018

Get a Swift class's property name as a String [duplicate]

This question already has an answer here:

How do I get the property name as a string?

class Person {
    var firstName: String
    var lastName: String
    var downloading: Bool

    func excludePropertiesFromCloud() -> [String] {
        return //here I want to return ["downloading"]
    }
}

I would like to avoid having to type return ["downloading"] to prevent errors if the name of the variable changes later on.

To get the class name you can use String(describing: Person.self), so I am looking at something similar for properties.





Aucun commentaire:

Enregistrer un commentaire