Swift: Undefined Symbols: iTunesApplication

I am currently trying to build a Swift OS X app and am having a hard time using ScriptingBridge.

I included the correct iTunes.h file and Xcode did not give any errors when I wrote "iTunesApplication" as type.

However, when I compile (run) the application, it gives me an error :( Does anyone know about this issue?

Undefined symbols for x86_64 architecture:
"_OBJC_CLASS _ $ _ iTunesApplication" referenced by:
     __TFC12LoveYouChloe11AppDelegate10showWindowfS0_FPSs9AnyObject_T_ in AppDelegate.o
ld:
clang not found symbol (s) for x86_64 architecture exit code: no linker exit code: v to make a call)

And here is my code:

var iTunes: iTunesApplication = SBApplication.applicationWithBundleIdentifier("com.apple.iTunes") as iTunesApplication
iTunes.playpause()

      

+3


source to share


2 answers


Instead

var iTunes: iTunesApplication = SBApplication.applicationWithBundleIdentifier("com.apple.iTunes") 

      

using

var iTunes: AnyObject = SBApplication.applicationWithBundleIdentifier("com.apple.iTunes")

      

Sometimes the compiler gets confused when you access two or more properties on a string (not sure why), so you might need to use a temporary variable. For example:.

Instead:



let songName: String = iTunes.playlists[0].songs[0].name

      

Try:

let song: AnyObject = iTunes.playlists[0].songs[0]
let songName = song.name

      

Or, conversely, faster (this also works if you declare iTunes

as SBApplication

):

let songName: String = iTunes.valueAtIndex(0, inPropertyWithKey: "playlists").valueAtIndex(0, inPropertyWithKey: "songs").valueForKey("name")

      

EDIT: You can also generate .swift headers as mentioned here: https://github.com/tingraldi/SwiftScripting

0


source


The best way to solve this is to take the generated Objective-C Scripting Bridge header and convert it to native Swift. I wrote a Python script ( here ) that can do this for you. You can see my answer here for a better explanation of what exactly is happening if you're interested.



0


source







All Articles