So, I want to do something like:
+ (void) replace_text_with: (NSString *) const predefined_text_style;
Where I’ve defined some text styles using constant strings in a Constants.h and Constants.m file elsewhere.
I want to require that the parameter passed as predefined_text_style is one of those constants, and if it’s impossible to specifically limit it to those constants, at least require that it be a constant of some kind. Is this possible?
My knowledge in Objective-C is a bit rusty but I bet it is not possible to restrict the parameters to a subset of strings. What I would recommend is to use enums:
Eventually, retrieve the constant strings based on the value of the enum:
As in:
This is not a too great solution because you can pass integers in place of the values of the enum, but at least the type of the parameter will document what you are expecting.
Another possibility is to create a new class whose instances will store the string constants. Those instances will be passed as parameters instead of strings. In theory, one can still create new instances of this class in addition to the ones used as constants, but it is harder to do it by accident than when using strings.
Anyway, I feel both solutions are unnecessary overhead. I would not worry about restricting the passable values too much (at least not in Objective-C – it could be far easier in some other languages). However, as I do not know much about your context, those are some possible solutions.