2
votes

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
2
MapViewController.h (or MapViewController.m), doe they have #import "GlobalVariables.h" ? And what's the class of MAP_SATELLITE_VIEW? Really a BOOL (because it's declared as a pointer in your code, but in loadVariables you don't seem to treat it as such.Larme
Yes I had, I also #import "GlobalVariables.h" to .pch filestudent
You don't need @synthesize and that ivar should not be a BOOL *, but just a BOOL. I'd also suggest naming the properties in the standard fashion; mapSatelliteViewEnabled`.bbum
Thank you @bbum for your valuable input.student

2 Answers

3
votes

I found the problem. On the .m file in xcode at the right, I had to tick the checkbox of the Target Membership.

2
votes

Make sure "GlobalVariables" is add in "Compile Sources". Build phases->Compile Source and add the file.