I want to set the rating of a track in Swift 2.3/3 using the iTunes ScriptingBridge framework. I have the Swift iTunes header with the protocol definition as this (full header here):
@objc protocol iTunesTrack: iTunesItem {
@objc optional var album: NSString {get set}
@objc optional var albumArtist: NSString {get set}
@objc optional var rating: Int {get set}
}
extension SBObject: iTunesTrack {}
But when I try to set the rating:
var iTunesApp = SBApplication(bundleIdentifier: "com.apple.iTunes") as! iTunesApplication
var currentTrack = iTunesApp.currentTrack
currentTrack.rating = 10
Xcode compiler gives me this error:
Cannot assign to property: 'currentTrack' is inmutable
How I make it mutable? I know this code works in Objective-C but I cannot make it work in Swift and it doesn't work using the Objective-C header and a Objective-C Bridging Header.