Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 02-24-2010, 10:08 AM   #7 (permalink)
RLScott
Registered Member
 
Join Date: Jun 2009
Location: Ypsilanti, Michigan
Age: 63
Posts: 1,549
RLScott is on a distinguished road
Default

The way to declare a global is to declare it outside of any @interface...@end block, and to define in outside of any @implementation...@end block, as in:

Code:
//this code goes under some .h file (it doesn't matter which one)
extern NSMutableArray *globalArray;

@interface (of some class - it doesn't matter which one)
...
@end
Then define globalArray as in:
Code:
NSMutableArray *globalArray;
@implementation (any, it doesn't matter which one)
...
@end
And then, somewhere where you are sure it will only be executed once:
Code:
globalArray = (some alloc-type of NSMutable Array creation method, retaining)
Now you have a singleton NSMutableArray you can access from anywhere. Just don't ever release it. It's memory will be reclaimed automatically when your app closes.

Robert Scott
Ypsilanti, Michigan
RLScott is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 175,526
Threads: 94,045
Posts: 402,623
Top Poster: BrianSlick (7,978)
Welcome to our newest member, iThoms
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:14 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.