Swift iTunes ScriptingBridge链接器错误 [英] Swift iTunes ScriptingBridge linker error
问题描述
我已经大量搜寻这个问题的答案,但没有找到,所以我在这里问。我想读使用SWIFT在iTunes当前曲目,但每当我尝试引用任何iTunes的类(iTunesApplication,iTunesTrack等),我得到以下错误:
适用于建筑x86_64的未定义符号:
$失败p $ p>
_OBJC_CLASS _ $ _ iTunesApplication,从引用:在iTunesWrapper.o $ b在iTunesWrapper.o
__TMaCSo17iTunesApplication
__TFC8WAILT_v213iTunesWrapper17getSongWithFormatfS0_FTSS3sepSS10timeOnLeftSb_SS $ b LD:符号(S)没有发现建筑x86_64的
铛:错误:连接命令,退出代码1(使用-v看看调用)
任何想法,为什么会这样?
谢谢,结果
-tlf
PS如果我使用Obj-C,它的工作就好了。它只有当我使用雨燕的错误。
解决方案由于斯威夫特的强静态类型的,它与它不代码链接问题没有一个实现或二进制。因此,要使用Objective-C的桥接报头有了它,你将很可能需要使用通用
SBObject
是因为斯威夫特知道这些的实施,即使你的.h声明其他类。
另一种方法是使用脚本生成一个可以看到和使用的带有声明的本地Swift文件。 这里是一个Python脚本(完全公开:它是我的)生成Objective-C脚本桥头然后创建一个本地Swift版本。这避免了链接器错误和上述SBObject通用类型。
I have searched extensively for an answer to this, but have found none, so I'm asking here. I am trying to read the current track in iTunes using Swift, but whenever I try to reference any of the iTunes classes (iTunesApplication, iTunesTrack, etc) I get the following error:
Undefined symbols for architecture x86_64: "_OBJC_CLASS_$_iTunesApplication", referenced from: __TFC8WAILT_v213iTunesWrapper17getSongWithFormatfS0_FTSS3sepSS10timeOnLeftSb_SS in iTunesWrapper.o __TMaCSo17iTunesApplication in iTunesWrapper.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
Any idea why this is happening?
Thanks,
-tlf
P.S. If I use Obj-C, it works just fine. It only errors when I am using Swift.解决方案Because of Swift's strong static typing, it has issues linking with code that it doesn't have either an implementation or a binary for. Therefore to use an Objective-C Bridging Header with it, you will most likely need to use generic
SBObject
s because Swift knows the implementation of those, even though your .h declares the other classes.An alternative is to use a script to generate a native Swift file with declarations that it can see and use. Here is a Python script (full disclosure: it's mine) that generates Objective-C Scripting Bridge headers then creates a native Swift version. This avoids Linker Errors and the aforementioned SBObject generic typing.
这篇关于Swift iTunes ScriptingBridge链接器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!