【问题标题】:Undefined symbols for architecture arm64: "_OBJC_CLASS_$_GlobalVariables", referenced from: objc-class-ref in MapViewController.o架构 arm64 的未定义符号:“_OBJC_CLASS_$_GlobalVariables”,引用自:MapViewController.o 中的 objc-class-ref
【发布时间】:2018-04-23 13:34:17
【问题描述】:

我正在尝试创建一个 Singleton,以便可以全局使用变量,但出现此错误:

架构 arm64 的未定义符号:
“_OBJC_CLASS_$_GlobalVariables”,引用自: MapViewController.o ld 中的 objc-class-ref:未找到架构 arm64 clang 的符号:错误:链接器命令失败并退出 代码 1(使用 -v 查看调用)

此问题的一些解决方案建议在构建阶段添加第三方库,但我不知道要添加哪个库。这是我的单例类:

.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

这就是我尝试从 MapViewController 访问 MAP_SATELLITE_VIEW 变量的方式:

 [GlobalVariables sharedInstance].MAP_SATELLITE_VIEW

【问题讨论】:

  • MapViewController.h(或MapViewController.m),他们有#import "GlobalVariables.h"吗? MAP_SATELLITE_VIEW 的类别是什么?真的是BOOL(因为它在您的代码中被声明为指针,但在loadVariables 中您似乎没有这样对待它。
  • 是的,我也有 #import "GlobalVariables.h" 到 .pch 文件
  • 你不需要@synthesize,并且那个ivar不应该是BOOL *,而只是BOOL. I'd also suggest naming the properties in the standard fashion; mapSatelliteViewEnabled`。
  • 感谢@bbum 的宝贵意见。

标签: ios objective-c xcode


【解决方案1】:

我发现了问题。在右侧 xcode 中的 .m 文件上,我必须勾选 Target Membership 的复选框。

【讨论】:

  • 你是最好的“学生”:)
【解决方案2】:

确保在“编译源”中添加“GlobalVariables”。构建阶段->编译源并添加文件。

【讨论】:

    猜你喜欢
    • 2015-05-07
    • 2012-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-28
    • 1970-01-01
    • 2018-05-23
    相关资源
    最近更新 更多