Accessing Method from other Classes Objective-C

前端 未结 8 1544
挽巷
挽巷 2020-11-29 05:57

Looked for an answer for this question, but I haven\'t found a suitable one yet. I\'m hoping you guys (and gals) can help me out! (This is for an iPhone app)

Alrig

8条回答
  •  盖世英雄少女心
    2020-11-29 06:49

    It sounds to me like the common code doesn't need to be in a class at all. Is there a reason you can't just use a C-style function for what you want to do?

    You could put the common code in a class and then make your other two classes subclasses of that one; this method also avoids the code duplication.

    Another option might be to write a class method instead of instance methods for this common code. I think most people feel that singletons are best avoided as a design choice.

    It would be easier to give a good answer if we knew more about what you were really trying to accomplish.

提交回复
热议问题