Goal C: Store Variables Available in All Views

Hi,

I am trying to write my first iPhone app. I have a need to have access to data in all views. Data is saved when the user logs in and should be available for all views after that.

I would like to create a static class, however, when I try to access the static class, my application crashes without output to the console.

Is this the only way to write data to a file? Or is there another clean solution that I haven't thought about?

Thank you very much in advance,

0
source share
2 answers

Use the singleton class, I always use them for global data manager classes that should be accessible from anywhere in the application. You can create an easy way:

@interface NewsArchiveManager : NetworkDataManager { } + (NewsArchiveManager *) sharedInstance; @end @implementation NewsArchiveManager - (id) init { self = [super init]; if ( self ) { // custom initialization goes here } return self; } + (NewsArchiveManager *) sharedInstance { static NewsArchiveManager *g_instance = nil; if ( g_instance == nil ) { g_instance = [[self alloc] init]; } return g_instance; } - (void) dealloc { [super dealloc]; } @end 
+7
source

I don't know what you mean by β€œstatic class”, but you want singleton . See this question for various setup methods.

+1
source

Source: https://habr.com/ru/post/925275/


All Articles