How or where should I store object instances that I require globally within my iOS app?

后端 未结 1 995
挽巷
挽巷 2020-12-11 23:51

I\'m building an iOS application. Most of the application requires access to a persistent object. This object is instantiated when the app loads via the Application Delegate

相关标签:
1条回答
  • 2020-12-12 00:05

    You might want to look at the Singleton pattern. The linked article provides a pretty good description of it including how to implement one in Cocoa.

    If the Singleton doesn't make sense in your context, and you still need the Global reference to your variable, you could just put a reference to it in your AppDelegate. (Not recommended)

    It can be accessed from within your application anytime using:

    [UIApplication sharedApplication] delegate]

    0 讨论(0)
提交回复
热议问题