Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
477 views
in Technique[技术] by (71.8m points)

iphone - Is it a bad practice to use your AppDelegate as your Singleton?

I'm sometimes using a Singleton (to store data that is used by several different classes) in my projects and I'm thinking why not use my AppDeletage, since it's already a Singleton and easy to access. Is this a bad practice and if so, why?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There is no right answer to this one. You'll get many opinions on this. I see no issue with using the AppDelegate, and I do it for all my apps:

  • The delegate is practically mandatory for iPhone apps,
  • it's there for the lifetime of the app;
  • and one can access it from anywhere in the program (although don't abuse that!).

One must remain vigilant though, so that code that doesn't necessarily have to be there, isn't there. You don't want your AppDelegate to become massive and unmaintainable.

The question has been answered before on StackOverflow:

Application Design and AppDelegate

The answers on that may help you also.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...