Hello,
I am trying to retrieve/set various properties for classes, e.g. 'speaking' of NSSpeechSynthesizer.
As far as I know, CocoaMessage() allows methods to be called, but it does not support properties. Is there a way to do this in PB?
Erion
[solved] (OSX) get/set cocoa property
[solved] (OSX) get/set cocoa property
Last edited by erion on Thu Sep 17, 2015 8:46 pm, edited 1 time in total.
To see a world in a grain of sand,
And a heaven in a wild flower,
Hold infinity in the palm of your hand,
And eternity in an hour.
- W. B.
Visit my site, also for PureBasic goodies http://erion.tdrealms.com
And a heaven in a wild flower,
Hold infinity in the palm of your hand,
And eternity in an hour.
- W. B.
Visit my site, also for PureBasic goodies http://erion.tdrealms.com
Re: (OSX) get/set cocoa property
A property is a combination of a getter and setter function or in case of readonly a getter function only.erion wrote:I am trying to retrieve/set various properties for classes, e.g. 'speaking' of NSSpeechSynthesizer.
As far as I know, CocoaMessage() allows methods to be called, but it does not support properties. Is there a way to do this in PB?
If you look at the documentation for NSSpeechSynthesizer, it says
So in this case the function you need is called isSpeaking@property(getter=isSpeaking, readonly) BOOL speaking
Code: Select all
SpeechSynthesizer = CocoaMessage(0, CocoaMessage(0, 0, "NSSpeechSynthesizer alloc"), "initWithVoice:$", @"com.apple.speech.synthesis.voice.Alex")
Debug CocoaMessage(0, SpeechSynthesizer, "isSpeaking")
CocoaMessage(0, SpeechSynthesizer, "startSpeakingString:$", @"Your Mac is speaking to you")
Delay(100)
Debug CocoaMessage(0, SpeechSynthesizer, "isSpeaking")
MessageRequester("", "Your Mac is speaking to you")
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
Re: (OSX) get/set cocoa property
Marvellous, thank you!
I wasn't expecting getter/setter exposure because of my Windows background, but this definitely makes things easier.
Now I wish we had native Cocoa type conversion, such as NSArray to PB array, etc.
Once again, huge thanks for your help!
I wasn't expecting getter/setter exposure because of my Windows background, but this definitely makes things easier.
Now I wish we had native Cocoa type conversion, such as NSArray to PB array, etc.

Once again, huge thanks for your help!
To see a world in a grain of sand,
And a heaven in a wild flower,
Hold infinity in the palm of your hand,
And eternity in an hour.
- W. B.
Visit my site, also for PureBasic goodies http://erion.tdrealms.com
And a heaven in a wild flower,
Hold infinity in the palm of your hand,
And eternity in an hour.
- W. B.
Visit my site, also for PureBasic goodies http://erion.tdrealms.com
Re: (OSX) get/set cocoa property
That would be very difficult.erion wrote:Now I wish we had native Cocoa type conversion, such as NSArray to PB array, etc.
To convert a PB string array for example, you would need to convert each item into a NSString also.
But when you convert an array of integer values, you would need a different approach.
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)