In my Swift project I need to communicate with iTunes via ScriptingBridge
framework. According to Apple documentation I create iTunes.h
file with sdef /Applications/iTunes.app | sdp -fh --basename iTunes
, then link ScriptingBridge.framework to project and create AppName-Bridging-Header.h file with #import "iTunes.h"
.
But when I try to get any of iTunes app property, e.g.
var iTunesApp: iTunesApplication? = SBApplication.applicationWithBundleIdentifier("com.apple.iTunes") as? iTunesApplication
let currentTrack: iTunesTrack? = iTunesApp?.currentTrack
I get linker error like
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_iTunesApplication", referenced from:
__TFC5NowP_14iTunesWorker21fetchCurrentTrackInfofS0_FT_T_ in iTunesWorker.o
__TFC5NowP_14iTunesWorkercfMS0_FT_S0_ in iTunesWorker.o
_get_field_types_iTunesWorker in iTunesWorker.o
"_OBJC_CLASS_$_iTunesTrack", referenced from:
__TFC5NowP_14iTunesWorker21fetchCurrentTrackInfofS0_FT_T_ in iTunesWorker.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I use Xcode 6 beta 4. Any ideas?
check this out, it uses Swift and it works (I tested it)
https://gist.github.com/bjhomer/fe8b3b05388b71ba0ab9
import ScriptingBridge
@objc protocol iTunesTrack {
optional var name: String {get}
optional var album: String {get}
}
@objc protocol iTunesApplication {
optional var soundVolume: Int {get}
optional var currentTrack: iTunesTrack? {get}
}
extension SBApplication : iTunesApplication {}
let app: iTunesApplication = SBApplication(bundleIdentifier: "com.apple.iTunes")
// Because these are all optional properties (to avoid providing an implementation), we have
// to use '!' to indicate we know the implementation exists.
let track: iTunesTrack? = app.currentTrack!
let album = track?.album!
let trackName = track?.name!
println("Current track: \(trackName) - \(album)")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With