iphone - Global variables and objects in Objective C. What is the best way? -


After

I want to use global variables and objects for iphone project.

I have created NSObject class and defined as below:

.h file:

  #import & lt ; Foundation / Foundation. H & gt; @ Interface Global Class: NSOBX Extension NSSSing * IISST; External NSMUttAbra * Armarta; @end   

Meter file:

  #import "GlobelClass.h" @implementation GlobelClass NSString * mystr; NSMutableArray * Arrdata; @end   

What is the best way or should I use the singleton pattern like the link answer below:

Share the idea

Text after "

The way in which to use the global variable in the application is:

You Application representative class can only be used>

.h file:

  app delegate: uirponder & lt; UIApplicationDelegate & gt; {} @property (non-rigorous, strong) NSString * strUserID;   

.m file:

  @ synthesis strUserID;   

You can now use strUserID as a global variable in your UIViewController:

  ABCProjectAppDelegate * AppDelegate = (ABCProjectAppDelegate *) [ UIApplication sharedApplication] representative];   

You can set the price:

  appDelegate.strUserID = @ "test";   

Get the value:

  NSString * strId = appDelegate.strUserID;   

:)

Comments

Popular posts from this blog

python - how we can use ajax() in views.py in django? -

matlab - Using loops to get multiple values into a cell -

python - Sequence Pattern recognition with Pybrain -