gpt4 book ai didi

swift - ScriptingBridge --> 无法分配给属性 : 'self' is immutable

转载 作者:行者123 更新时间:2023-11-30 10:01:38 34 4
gpt4 key购买 nike

我正在使用脚本桥从我的 osx 应用程序控制 Spotify。

我正在创建一个应用程序对象,如下所示:

var spotify: AnyObject = SBApplication(bundleIdentifier: "com.spotify.client")!

然后当我尝试这样做时:

spotify.soundVolume = 10

我收到错误

 cannot assign to property: 'self' is immutable

我做错了什么?我应该能够根据 Spotify 的文档设置音量:https://developer.spotify.com/applescript-api/

/*
* Spotify.h
*/

#import <AppKit/AppKit.h>
#import <ScriptingBridge/ScriptingBridge.h>


@class SpotifyApplication, SpotifyTrack, SpotifyApplication;

enum SpotifyEPlS {
SpotifyEPlSStopped = 'kPSS',
SpotifyEPlSPlaying = 'kPSP',
SpotifyEPlSPaused = 'kPSp'
};
typedef enum SpotifyEPlS SpotifyEPlS;



/*
* Spotify Suite
*/

// The Spotify application.
@interface SpotifyApplication : SBApplication

@property (copy, readonly) SpotifyTrack *currentTrack; // The current playing track.
@property NSInteger soundVolume; // The sound output volume (0 = minimum, 100 = maximum)
@property (readonly) SpotifyEPlS playerState; // Is Spotify stopped, paused, or playing?
@property double playerPosition; // The player’s position within the currently playing track in seconds.
@property (readonly) BOOL repeatingEnabled; // Is repeating enabled in the current playback context?
@property BOOL repeating; // Is repeating on or off?
@property (readonly) BOOL shufflingEnabled; // Is shuffling enabled in the current playback context?
@property BOOL shuffling; // Is shuffling on or off?

- (void) nextTrack; // Skip to the next track.
- (void) previousTrack; // Skip to the previous track.
- (void) playpause; // Toggle play/pause.
- (void) pause; // Pause playback.
- (void) play; // Resume playback.
- (void) playTrack:(NSString *)x inContext:(NSString *)inContext; // Start playback of a track in the given context.

@end

// A Spotify track.
@interface SpotifyTrack : SBObject

@property (copy, readonly) NSString *artist; // The artist of the track.
@property (copy, readonly) NSString *album; // The album of the track.
@property (readonly) NSInteger discNumber; // The disc number of the track.
@property (readonly) NSInteger duration; // The length of the track in seconds.
@property (readonly) NSInteger playedCount; // The number of times this track has been played.
@property (readonly) NSInteger trackNumber; // The index of the track in its album.
@property (readonly) BOOL starred; // Is the track starred?
@property (readonly) NSInteger popularity; // How popular is this track? 0-100
- (NSString *) id; // The ID of the item.
@property (copy, readonly) NSString *name; // The name of the track.
@property (copy, readonly) NSString *artworkUrl; // The URL of the track%apos;s album cover.
@property (copy, readonly) NSImage *artwork; // The property is deprecated and will never be set. Use the 'artwork url' instead.
@property (copy, readonly) NSString *albumArtist; // That album artist of the track.
@property (copy) NSString *spotifyUrl; // The URL of the track.


@end



/*
* Standard Suite
*/

// The application's top level scripting object.
@interface SpotifyApplication (StandardSuite)

@property (copy, readonly) NSString *name; // The name of the application.
@property (readonly) BOOL frontmost; // Is this the frontmost (active) application?
@property (copy, readonly) NSString *version; // The version of the application.

@end

最佳答案

事实证明,一个可行的选择是实际做这样的事情:

spotify.setValue(sender.integerValue, forKey: "soundVolume")

关于swift - ScriptingBridge --> 无法分配给属性 : 'self' is immutable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38190603/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com