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

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -