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()
source to share
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
source to share