I am writing a class that has many class variables. So I am declaring the variables as static in my .m file and before @implementation statement, with setters and getters for them as class methods. Is it a good idea to do this for lets say more than 10 class variables? Or is there a better alternative to do this?
-
2Why don't you describe the problem you are trying to solve with such a class and lots of class methods. Without more info about what you are trying to do, it will be hard to get a good answer. And be sure to put the extra details in your question and not in comments.rmaddy– rmaddy2014-08-11 18:07:29 +00:00Commented Aug 11, 2014 at 18:07
-
Asking questions without accepting answers: bad form. People are trying to help you!tooluser– tooluser2014-08-20 18:14:45 +00:00Commented Aug 20, 2014 at 18:14
2 Answers
Without more information that's a tough call. Technically working - yes.
I know many people don't like singletons, but maybe this is one of the good use cases for it?
Maybe you find that configuring one of those classes, or now objects, really doesn't have to be a singleton at all?
Just because there is only one instance of a given class doesn't mean in cannot be a "normal" class.
Class variables often mystify your state all over your code base and make debugging and code reuse a pain. Let alone multi threading.
Edit: Given your usecase as described in a comment to another answer, I'd go with a singleton, i.e. a 'SoundPlayer' class. '[[SoundPlayer sharedInstance] playCoolSound];' is easy, and you get proper instance variables there, too. And you can always exchange it for another class if needed (think test cases etc.).
Comments
Well, I can guarantee that the computer will have no problem with it. They're pretty good with large numbers.
Without knowing more about your situation, it's hard to say. It does sound, though, like you're potentially going about it in a way that isn't optimal. It's good that you followed your intuition and are asking about it. Perhaps you should modify your question (or ask a new one and link it here) to talk about what you really want to accomplish, and then we can help.