无法让 tnoodle-lib-objc 在 swift 中工作



我正在编写一个speedcubing计时器,我正试图让tnoodle-lib库(链接在这里)与我的Xcode项目一起工作。到目前为止,我已经成功地导入了我认为的一切,但我不知道如何实际生成它的混乱。有人能帮帮我吗?

下面是我要做的:

在我的Header.h桥接文件:

#ifndef Bridging_Header_h
#define Bridging_Header_h
#import "org/worldcubeassociation/tnoodle/scrambles/PuzzleRegistry.h"
#import "org/worldcubeassociation/tnoodle/scrambles/Puzzle.h"
#import "org/worldcubeassociation/tnoodle/svglite/Svg.h"
#import "org/worldcubeassociation/tnoodle/svglite/Dimension.h"
NSString * const SCRAMBLE = "/("NSSOrgWorldcubeassociationTnoodleScramblesPuzzleRegistry_get_THREE())"
#endif /* Bridging_Header_h */

在我的项目构建设置中,我导入了tnoodle-lib-objc的东西,就像它在github页面上说的。我不知道的是如何实际使用它来生成乱序,因为看起来你会在java中这样做,我不知道如何将它从java转移到swift。

我认为理解桥接头的作用是很好的。当我们使用Objective-C代码时,我们需要"桥接"。这段代码可以在Swift中使用——这就是桥接头的目的。它应该只作为我们需要的Objective-C代码的中介,也就是import语句。

对于一个非常简单的方法,您的桥接头应该看起来像这样:

#ifndef Bridging_Header_h
#define Bridging_Header_h
#import "org/worldcubeassociation/tnoodle/scrambles/PuzzleRegistry.h"
#import "org/worldcubeassociation/tnoodle/scrambles/Puzzle.h"
#endif

这使我们能够访问tnoodle Puzzle和PuzzleRegistry组件。

从这里开始,在我们的Swift代码中-在主程序的任何地方,您应该能够调用扰频器。例如:

OrgWorldcubeassociationTnoodleScramblesPuzzleRegistry.TWO.getScrambler().generateScramble()

.TWO为乱序类型,可以是.THREESQ1、任意乱序类型。如果您参考tnoodle仓库,您可以看到它们是如何用方法定义它们的Puzzle的。每种"谜题类型"有一个.getScrambler()方法,它返回一个OrgWorldcubeassociationTnoodleScramblesPuzzle对象,然后可以调用.generateScramble()。这将产生对您所选择的谜题类型的争夺。

要注意返回的对象是可选的,你需要展开来获得String。

最新更新