tingraldi / SwiftScripting

Utilities and samples to aid in using Swift with the Scripting Bridge. If you want to automate tasks on your Mac, but don't like AppleScript, this is for you.
285 stars 29 forks source link

Reduce the need for a bridging header #4

Closed demosdemon closed 9 years ago

demosdemon commented 9 years ago

I recently discovered that there's a typealias in ScriptingBridge called AEKeyword which is the type expected for SBObject.propertyWithCode(_:). It's aliased to FourCharCode which itself is aliased to UInt32. You could reduce the need for the bridging header by unpacking all off the enums' FourCharCodes into a uin32 literal value and adding them to the swift file.

So the following C enum would translate to the Swift Enum:

enum iTunesEKnd {
  iTunesEKndTrackListing = 'kTrk' /* a basic listing of tracks within a playlist */,
  iTunesEKndAlbumListing = 'kAlb' /* a listing of a playlist grouped by album */,
  iTunesEKndCdInsert = 'kCDi' /* a printout of the playlist for jewel case inserts */
};
typedef enum iTunesEKnd iTunesEKnd;
enum iTunesEKind : AEKeyword {
  case iTunesEKndTrackListing = 0x6b54726b
  case iTunesEKndAlbumListing = 0x6b416c62
  case iTunesEKndCdInsert = 0x6b434469
}
tingraldi commented 9 years ago

Thank you for your suggestion. I was somewhat on the fence about Swiftifying the enums. I'll take another look at this option. Feel free to submit a pull request if you've already done the work related to this.