Page 1 of 1

SwiftMessage function the horizon?

Posted: Sun Jun 02, 2024 2:00 pm
by mrbungle
The Cocoamessage function is very useful for macOS users, but over time, Cocoa has been progressively phased out. Will a future version of PB support an equivalent for Swift functions?

Thank you

Re: SwiftMessage function the horizon?

Posted: Sun Jun 02, 2024 4:58 pm
by wilbert
Did you encounter any methods you can't call ?

From what I understand both Swift and Objective-C use objc_msgSend which is also what CocoaMessage does.

Re: SwiftMessage function the horizon?

Posted: Sun Jun 02, 2024 5:07 pm
by mrbungle
Good to know. It seems some functions like the Swift UI's switch button toggle may only be available in Swift, but I could be wrong.

Re: SwiftMessage function the horizon?

Posted: Sun Jun 02, 2024 5:53 pm
by r-i-v-e-r
wilbert wrote: Sun Jun 02, 2024 4:58 pm Did you encounter any methods you can't call ?

From what I understand both Swift and Objective-C use objc_msgSend which is also what CocoaMessage does.
This isn't strictly accurate.

Swift code can interop with Obj-C APIs relatively simply (using objc_* / sel_* / class_* functions under-the-hood), but there do exist some Swift-only APIs which are unavailable to Obj-C (at least trivially speaking, i.e., they lack Obj-C runtime bridging).

In general, Swift is less dynamic than Obj-C. So for something like SwiftUI, you'd import functions directly from the framework and call them in accordance with the Swift calling convention. You can do this in PureBasic (or C/Obj-C/etc.), but it'll be somewhat of a pain using anything but Swift as you've got to care for runtime specifics, name (de)mangling, etc. For this same reason, a SwiftMessage(...) function makes less sense.

Re: SwiftMessage function the horizon?

Posted: Sun Jun 02, 2024 6:07 pm
by mrbungle
Thank you for clarifying