1

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.

thislooksfun
  • 1,049
  • 10
  • 23
  • Possible duplicate of http://stackoverflow.com/questions/27395805/swift-undefined-symbols-itunesapplication – Pranav May 09 '15 at 06:25

1 Answers1

1

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 SBObjects 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.

Garrett
  • 5,580
  • 2
  • 31
  • 47
  • Since the introduction of AppleScriptObjC in Snow Leopard the Scripting Bridge framework is pretty obsolete. The integration with Objective-C and Swift is quite easy and AppleScriptObjC much faster than SB – vadian Jun 27 '15 at 17:54
  • 1
    Too bad there isn't a AppleScriptSwift… – geowar Dec 15 '15 at 17:02