Support Topics Documentation Slack YouTube Blog

Custom columns on BackendlessUser model - direct access to fields

Hello,
I’m reading through the docs, and it seems as if we need to use properties when dealing with custom columns on our main Users table. We would like to use this User/BackendlessUser structure so we can get and retrieve custom columns (gender, etc) without having to have a different User-type object.

But it seems the only way to get or set these for the default BackendlessUser implementation is to get or provide a full list of properties each time. This seems like a bit of overhead of code, when it would be great to somehow add our own Swift-side fields and just access/retrieve them with direct access to the fields (and subsequently update the user after setting individual ones).

Are there any tricks to accomplishing this on the app side that you guys have seen, possibly utilizing an extension on BackendlessUser? If not, no worries, but just wanted to check, as this will greatly simplify code on the app side if there exists a solution out there.

Thanks!

I came up with the following for easy retrieval/setting of custom properties/columns, although I’m not sure if there’s a better way:

extension BackendlessUser {
    var testColumn: String {
        get {
            self.properties["testColumn"] as! String
        }
        set {
            self.properties["testColumn"] = newValue
        }
    }
    //... add other columns as needed
}

Hello @vincent-guerin,
We don’t recommend to change the BackendlessUser class as it is the system one. If the extension works and fits your needs of course you can use it, however we cannot provide any
guarantees about this case.

Regards,
Olha

Thanks, Olha. I wasn’t planning on changing the actual class, but I think with some clever extensions, I can get it working and clean. Thank you for your help!