ios - 无法在类初始值设定项中生成 NSUUID - Apple Mach-O 链接器错误

标签 ios objective-c uuid nsuuid

我正在使用 Sprite Kit 编写 iOS 游戏(因此针对 iOS 7+),并且在初始化 gameObject (自定义类)时遇到问题。

如果我尝试为游戏 ID 设置 UUID,则构建会失败(请参阅下面的错误消息);删除对 getUUID 方法的调用可以解决问题,因此我很确定这就是问题所在。

getUUID 方法位于辅助类内,该类在 Prefix.pch 中导入(因此应该可用于所有其他文件?)。

这是helpers.h:

NSString *getUUID();

@interface helpers : NSObject

@end

helpers.m:

@implementation helpers

+(NSString *)getUUID
{
    NSUUID *uuid = [NSUUID UUID];
    NSString *uuidString = [uuid UUIDString];

    return uuidString;
}

@end

最后,这是 gameObject.m 的样子:

static NSString *gameID = nil;
static NSDate *gameStarted = nil;
static NSNumber *venue = nil;
static NSNumber *timerDuration = nil;
static NSArray *players = nil;
static NSArray *playerMoves = nil;
static NSNumber *winner = nil;

@implementation gameObject

+(void) initialize
{
    if(! gameID)
    {
        // generate a new guid for this game
        gameID = getUUID();
    }
}

@end

我得到的错误是:

Undefined symbols for architecture i386:
  "_getUUID", referenced from:
      +[gameObject initialize] in gameObject.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我已经检查了针对此错误提到的所有常见修复:我的build设置架构设置为 arm64 arm7 arm7s,文件的目标设置正确,并且我的所有 .m 文件包含在构建中。

有什么我哪里出错的想法吗?我对 Objective-C 还很陌生,所以目前所有这些对我来说都有点摸不着头脑。

最佳答案

您的 helpers.h 文件声明一个函数:

NSString *getUUID();

helpers.m 文件定义了一个类方法:

+(NSString *)getUUID;

这不一样。所以你必须决定你想要哪一个。例如,改变 .h 文件到

@interface helpers : NSObject
+(NSString *)getUUID;
@end

然后这样调用它

gameID = [helpers getUUID];

(旁注:类名通常以大写字母开头:“Helpers”。)

关于ios - 无法在类初始值设定项中生成 NSUUID - Apple Mach-O 链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21673076/

相关文章:

ios - 在 WatchKit 中,从 Modal View 调用 presentControllerWithName 将呈现 View 锚定为 root

iphone - UITextField 编辑部分字符串

ios - CoreData : Fetch and sort results in the order they were created, 不使用时间戳

MySQL:有没有一种简单的方法可以将 UUID 转换为整数?

ios - 当用户前往特定位置时向他们发送推送通知 [IOS]

ios - 高度等于 Swift 中 CustomCell 的最大高度的 CollectionView

ios - 是否可以使用 Core Graphics 绘制到各个 channel ?

objective-c - ld : library not found for -lIOKit. clang xcode

c# - 如何在.NET中获取磁盘的分区UUID

JavaScript:GUID 冲突