2

I'm trying to convert the Scripting Bridge header generated by sdef and sdp into Swift in order to be able to use it without a bridging header and obj-c wrapper. I think I came pretty close with the help of SwiftingBridge but I'm still facing an issue with properties or return values of type SBElementArray<iTunesAirPlayDevice> and NSArray<iTunesAirPlayDevice> for instance. If I let them like this I'm faced with issues Cannot specialize non-generic type 'SBElementArray' and so on.

Can I convert that part of the objective C code into Swift ?

Example objective C code:

// The application program
@interface iTunesApplication : SBApplication

- (SBElementArray<iTunesAirPlayDevice *> *) AirPlayDevices;
- (SBElementArray<iTunesBrowserWindow *> *) browserWindows;
- (SBElementArray<iTunesEncoder *> *) encoders;
- (SBElementArray<iTunesEQPreset *> *) EQPresets;
- (SBElementArray<iTunesEQWindow *> *) EQWindows;
- (SBElementArray<iTunesPlaylistWindow *> *) playlistWindows;
- (SBElementArray<iTunesSource *> *) sources;
- (SBElementArray<iTunesVisual *> *) visuals;
- (SBElementArray<iTunesWindow *> *) windows;
// ...
@property (copy) NSArray<iTunesAirPlayDevice *> *currentAirPlayDevices;  // the currently selected AirPlay device(s)
// ...
beeb
  • 1,187
  • 11
  • 32
  • You need to do something like this: https://gist.github.com/bjhomer/fe8b3b05388b71ba0ab9 ScriptingBridge is almost unusable in Swift, it's just too dynamic. After trying to use it for a while I eventually gave up and used NSAppleScript instead – Kametrixom Dec 04 '15 at 13:31
  • I saw that gist but it doesn't show how to do it for SBElementArray and that's not what I want to do anyway.. I'll see about NSAppleScript, it will probably suit me better, but my question remains. – beeb Dec 05 '15 at 17:24

1 Answers1

2

I was able to get it to work by just changing the code to return native array objects:

@objc protocol iTunesApplication {
//...
optional func AirPlayDevices() -> [iTunesAirPlayDevice]
optional func browserWindows() -> [iTunesBrowserWindow]
optional func encoders() -> [iTunesEncoder]
optional func EQPresets() -> [iTunesEQPreset]
optional func EQWindows() -> [iTunesEQWindow]
optional func playlistWindows() -> [iTunesPlaylistWindow]
optional func sources() -> [iTunesSource]
optional func visuals() -> [iTunesVisual]
optional func windows() -> [iTunesWindow]
optional var AirPlayEnabled: Bool {get}
//...
}