【问题标题】:Swift: Undefined Symbols: iTunesApplicationSwift:未定义符号:iTunesApplication
【发布时间】:2015-02-08 08:10:13
【问题描述】:

我现在正在尝试创建 Swift OS X 应用程序,但发现使用 ScriptingBridge 有困难。

我包含了正确的 iTunes.h 文件,当我将“iTunesApplication”写为类型时,Xcode 没有给出任何错误。

但是,当我编译(运行)应用程序时,它给了我错误:( 有人知道这个问题吗?

架构 x86_64 的未定义符号:
“_OBJC_CLASS__$_iTunesApplication”,引用自:
__TFC12LoveYouChloe11AppDelegate10showWindowfS0_FPSs9AnyObject_T_ 在 AppDelegate.o
ld:未找到体系结构 x86_64 的符号
clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)

这是我的代码:

var iTunes: iTunesApplication = SBApplication.applicationWithBundleIdentifier("com.apple.iTunes") as iTunesApplication
iTunes.playpause()

【问题讨论】:

  • 我可以重现这个。起初我以为只是你没有链接到 ScriptingBridge 框架,但这似乎并没有为我解决这个问题......

标签: macos cocoa swift itunes scripting-bridge


【解决方案1】:

解决这个问题的最佳方法是获取生成的 Objective-C Scripting Bridge 标头并将其转换为原生 Swift。我写了一个 Python 脚本 (here) 可以为你做到这一点。如果您有兴趣,可以查看我的回答 here,以便更好地了解具体情况。

【讨论】:

  • 我试过你的脚本,不幸的是它仍然会为 iTunes 产生 85 个错误...还有一些功能不起作用,例如我无法设置 soundVolume 属性...
【解决方案2】:

代替

var iTunes: iTunesApplication = SBApplication.applicationWithBundleIdentifier("com.apple.iTunes") 

使用

var iTunes: AnyObject = SBApplication.applicationWithBundleIdentifier("com.apple.iTunes")

有时当您连续访问两个或多个属性时编译器会感到困惑(不知道为什么),因此您可能需要使用临时变量。例如:

代替:

let songName: String = iTunes.playlists[0].songs[0].name

试试:

let song: AnyObject = iTunes.playlists[0].songs[0]
let songName = song.name

或者更快(如果您将iTunes 声明为SBApplication,这也有效):

let songName: String = iTunes.valueAtIndex(0, inPropertyWithKey: "playlists").valueAtIndex(0, inPropertyWithKey: "songs").valueForKey("name")

编辑: 您还可以生成此处指定的 .swift 标头:https://github.com/tingraldi/SwiftScripting

【讨论】:

  • 如何让您访问播放列表(这不是 AnyObject 的属性)
  • 对我也不起作用,实际上它甚至无法编译。
猜你喜欢
  • 1970-01-01
  • 2014-11-07
  • 2021-03-12
  • 1970-01-01
  • 2015-04-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-25
相关资源
最近更新 更多