Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift and ScriptingBridge.framework

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?

like image 687
Akki Avatar asked Nov 10 '22 04:11

Akki


1 Answers

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)")
like image 149
quemeful Avatar answered Nov 15 '22 04:11

quemeful