I use an NSMutableDictionary
to save objects.
Now I wanna access these objects in Swift
.
But when I create var player
in Swift, the saved objects are no longer accessible when I invoke the property. How can I solve this problem?
I tried to get access like described here. I can invoke the method player.remoteAccess
in Swift, but the Dictionary is empty. In Objective-C I have access to the content.
Thank you :)
PlayerClass.h
@interface PlayerClass : NSObject {
}
@property (nonatomic, readwrite) NSMutableDictionary *property;
-(void)playTextToSpeech;
-(void)remoteAccess;
PlayerClass.m
@implementation PlayerClass
@synthesize property = _property;
-(id)init
{
self = [super init];
if (self != nil)
{
_property = [[NSMutableDictionary alloc] init];
}
return self;
}
-(void)playTextToSpeech
{
_property[@"module_id"] = [[AudioPlayer alloc] initWithSocket:_socket moduleID:[@"module_id"]];
NSLog(@"property: %@", _property.description) // objects accessible
}
-(void)remoteAccess
{
NSLog(@"remoteAccess method ran");
NSLog(@"%@", _property.description);
}
Swift
@objc class AudioPlayer: NSObject, AVAudioPlayerDelegate {
var player: PlayerClass = PlayerClass()
self.invokePlayerClass()
func invokePlayerClass() {
player.remoteAccess() // empty
}
}