Reputation: 349
I am have one class named country , it has three NSMutableArray
country_name, latitude and longitude. i need the object of country class in whole application. So how to declare country class object as global object?
Upvotes: 0
Views: 186
Reputation: 7344
You can use the singleton design pattern and make a global object. But in general global variables / objects / singletons are a hint that something with your design is wrong.
Create a singleton this way:
+ (CardPainter*) sharedPainter {
static CardPainter* sp;
static dispatch_once_t token;
dispatch_once(&token, ^{
sp = [[CardPainter alloc] init];
});
return sp; }
Upvotes: 1
Reputation: 448
I recommend singleton like solution. Here is apple documentation with some explanation.
http://alexefish.com/post/15968663296/understanding-and-creating-singletons-in-objective-c
Upvotes: 0