SwiftScripting
SwiftScripting copied to clipboard
Why is everything an Int?
I did
sdef /Applications/iTunes.app > iTunes.sdef
sdp -fh --basename iTunes iTunes.sdef
sbhc.py iTunes.h
sbsc.py iTunes.sdef
and added the resulting Swift files to my project and fixed iTunes.swift so that it compiled (as explained in another issue). But I still am not able to interrogate iTunes usefully because everything in iTunes.swift is typed as an Int. For example:
// MARK: iTunesItem
@objc public protocol iTunesItem: SBObjectProtocol, iTunesGenericMethods {
@objc optional var container: Int { get } // the container of the item
@objc optional func id() // the id of the item
@objc optional var index: Int { get } // The index of the item in internal application order.
@objc optional var name: Int { get } // the name of the item
@objc optional var persistentID: Int { get } // the id of the item as a hexadecimal string. This id does not change over time.
@objc optional var properties: Int { get } // every property of the item
@objc optional func download() // download a cloud track or playlist, or a podcast episode
@objc optional func reveal() // reveal and select a track or playlist
@objc optional func setName(_ name: Int) // the name of the item
@objc optional func setProperties(_ properties: Int) // every property of the item
}
extension SBObject: iTunesItem {}
The container is an Int. The name is an Int. The properties is an Int. That's just wrong. The Objective-C file iTunes.h has this:
@interface iTunesItem : SBObject <iTunesGenericMethods>
@property (copy, readonly) SBObject *container; // the container of the item
- (NSInteger) id; // the id of the item
@property (readonly) NSInteger index; // The index of the item in internal application order.
@property (copy) NSString *name; // the name of the item
@property (copy, readonly) NSString *persistentID; // the id of the item as a hexadecimal string. This id does not change over time.
@property (copy) NSDictionary *properties; // every property of the item
- (void) download; // download a cloud track or playlist, or a podcast episode
- (void) reveal; // reveal and select a track or playlist
@end
Clearly, the container is an SBObject, the name is an NSString, and the properties is an NSDictionary. The Python script is being given the right types but is generating the wrong types.
I can fix this by editing all the types by hand. For example, everything works fine if I write
@objc optional var name: String { get } // the name of the item
But if I have to do that for every property, the Python script is not really being very helpful to begin with.
Thank you for filling an issue. In previous releases of macOS, this problem was solved by installing the Xcode command line tools. This no longer is sufficient on 10.13 or 10.14. I haven't yet found a solution.
Thanks for the response. It would be a kindness to inform people in the ReadMe that SwiftScripting is broken in current macOS system versions.
Point taken. I've updated the README. Thank you again.
@mattneub : We can once again remove that notice from the README file :D 🥳 🎉 See this PR why.