Swift iTunes ScriptingBridge linker error

I have searched for the answer to this question many times but haven't found any, so I ask here. I'm 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
Postscript If I use Obj-C it works fine. These are only errors when I use Swift.

+1


source to share


1 answer


Due to Swift's strong static typing, it has problems with code that it doesn't have either to implement or binary. So to use Objective-C Bridging Header with it, you will most likely need to use generic SBObject

because Swift knows about their implementation even though your .h declares other classes.



An alternative is to use a script to create your own Swift file with declarations that it can see and use. Here is a Python script (full disclosure: it's mine) that generates Objective-C script script headers and then builds its own version of Swift. This avoids linker errors and the aforementioned typical SBObject input.

+1


source







All Articles