Quote:
Originally Posted by WaRcLaWz
Sure.
I created a blank foundation class called "Globals" that stores the variables.
Globals.h looks like this...
Code:
#import <Foundation/Foundation.h>
extern NSArray *gMapArray;
extern NSMutableArray *gPathHexArray;
extern NSMutableArray *gTerrainImageViewArray;
@interface Globals : NSObject {
}
@end
Globals.m looks like this...
Code:
#import "Globals.h"
@implementation Globals
NSArray *gMapArray;
NSMutableArray *gPathHexArray;
NSMutableArray *gTerrainImageViewArray;
@end
The external variables need to be initialized before they can be used, so I did this in the "AppDelegate.m" class...
Code:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after app launch
[window addSubview:mainMenuViewController.view];
[window makeKeyAndVisible];
//Initialize array that holds the terrain graphics
gMapArray = [[NSArray alloc] init];
//Initialize array that holds the movement hexes
gPathHexArray = [[NSMutableArray alloc] init];
//Initialize array that holds the terrain UIImageView objects
gTerrainImageViewArray = [[NSMutableArray alloc] init];
}
You must make sure that you import the "Globals.h" into any class that uses the external variables, including the AppDelegate that I mentioned above. For example, in the "AppDelegate.m" you would make sure to have
Code:
#import "Globals.h"
I hope this helps! 
|
Hello~I have known your method, but I still have a question that do i need to write "Global *global=[[Global alloc] init];" before i use those global variables? Thank you~!