"This is a constant; its value can't be changed" error

@JuliaTruchsess the other option is to use something like a computed property that only has a setter that returns the value of the function

You can even set it as a static in the getter and ski calling the function more than once

This way it ACTS as a constant (unchangeable) and can be used in most places exactly the same

There are still ways you cant use it like a normal constant like #pragmas and #constant values in property default values

1 Like

Thatโ€™s a good solution for some cases, thanks, Norman. In my case, the constants only apply within their particular method, which is an overloaded constructor - theyโ€™re different in each variation of the constructor, so it would be messy to clutter the class or a module with all the different values. I just made them variables, and they go out of scope outside the method so donโ€™t take significant memory. I could also of course just use literals within the methods, but giving them names makes for better readability.