I am trying to create a Singleton so I can use a variable globally but I get this error:
Undefined symbols for architecture arm64:
"_OBJC_CLASS_$_GlobalVariables", referenced from: objc-class-ref in MapViewController.o ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
Some solutions to this problem suggest adding a third-party library in build phases, but I don't know which library to add. Here is my Singleton class:
.h
@interface GlobalVariables : NSObject
@property BOOL *MAP_SATELLITE_VIEW;
+ (GlobalVariables*)sharedInstance;
@end
.m
#import <Foundation/Foundation.h>
#import "GlobalVariables.h"
@implementation GlobalVariables
@synthesize MAP_SATELLITE_VIEW;
#pragma mark Singleton Methods
+ (GlobalVariables*)sharedInstance {
static GlobalVariables *obj = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
obj = [[self alloc] init];
[obj loadVariables];
});
return obj;
}
- (void)loadVariables {
self.MAP_SATELLITE_VIEW = NO;
}
@end
This is how I am trying to access the MAP_SATELLITE_VIEW variable from MapViewController:
[GlobalVariables sharedInstance].MAP_SATELLITE_VIEW
MapViewController.h
(orMapViewController.m
), doe they have#import "GlobalVariables.h"
? And what's the class ofMAP_SATELLITE_VIEW
? Really aBOOL
(because it's declared as a pointer in your code, but inloadVariables
you don't seem to treat it as such. – Larme@synthesize
and that ivar should not be aBOOL *
, but just aBOOL. I'd also suggest naming the properties in the standard fashion;
mapSatelliteViewEnabled`. – bbum