1
votes

I've been trying to use, in a swift code, the various SBElementArray generators defined in the iTunes.h ScriptingBridge header, for example:

  • List of playlists: (SBElementArray<iTunesPlaylist *> *) playlists;
  • List of artworks associated to a track: (SBElementArray<iTunesArtwork *> *) artworks;

But when i try to use a method associated to the type contained in those array:

let playlists: SBElementArray = iTunes.playlists()
if let playlist = playlists[0] as? iTunesPlaylist {
    print(playlist.name)
}

I get a compile error:

Undefined symbols for architecture x86_64:
 "_OBJC_CLASS_$_iTunesPlaylist", referenced from:
  objc-class-ref in AppDelegate.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

This seems to be limited to the SBElementArray as I have no problem accessing current track name with the following :

let track: iTunesTrack = iTunes.currentTrack;
print(track.name)

I'm also guessing that it has something to do with the type casting I'm trying to do from 'anyObject' to 'iTunesPlaylist' in my code (which i think i need to be bale to access the playlist content or whatever artwork i would like to display), because the following code:

let playlists: SBElementArray = iTunes.playlists()
print(playlists[0])
print(type(of: playlists[0]))

corectly returns:

<ITunesPlaylist @0x6080000402d0: ITunesPlaylist 0 of application "iTunes" (93931)>
ITunesPlaylist
1
One difference I notice is: I vs i (iTunesPlaylist/ITunesPlaylist) - Dave Weston
Yes, I noticed. I actually tried to add the class ITunesPlaylist (with capital i) to the iTunes.h file in desperation, but it didn't change the result. I'm going to give it another go, more carefully, just to make sure - Ericvulpi
So i tried replacing every iTunesPlaylist with ITunesPlaylist (with capital i) this time, both in the iTunes.h file and in my AppDelegate.swift file. Still get the same compile error. - Ericvulpi
The exact same error? Or does it have an upper case I now? - Dave Weston
You right, it has a upper case now : Undefined symbols for architecture x86_64: "_OBJC_CLASS_$_ITunesPlaylist", referenced from: objc-class-ref in AppDelegate.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) - Ericvulpi

1 Answers

0
votes

The downcasting is trying to create an optional and initialize an iTunesPlaylist that is not allowed and not present in the linker. Force it as you always know it to be a iTunesPlaylist or check the type.

if playlists.count > 0 {
    let playlist : = playlists[0]
    if playlist is iTunesPlaylist {
        print(playlist.name)
    }
}