5

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?

Akki
  • 1,487
  • 14
  • 25

2 Answers2

1

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)")
quemeful
  • 9,542
  • 4
  • 60
  • 69
  • sorry, I was in a hurry and saw a fellow programmer in need – quemeful May 17 '16 at 23:13
  • 1
    Nice update. No need to hurry on a question asked almost two years ago. If they were holding their breath, they're not going to need the answer anymore. – Mogsdad May 17 '16 at 23:23
0

I've found that linker errors gone when I get property with valueForKey(key: String?). So this problem seems like imperfection of beta version of Swift.

Akki
  • 1,487
  • 14
  • 25
  • I am getting the same error with just the first line: (var iTunesApp: iTunesApplication? = ...). Have you figured anything else out about a fix for this error? – Tom Locke Oct 25 '14 at 12:18
  • @TomLocke , no, I haven't. I've decided for myself that Swift still is too early to use in commercial projects. – Akki Oct 27 '14 at 08:47