Since Objective-C is more low level language than Swift, are there things that can be implemented in Objective-C whereas in, directly, Swift - not? For MacOS. For instance, working with hardware.
Swift do not support objc’s __attribute__((constructor))
Swift is turing-complete, so it can do anything if you don't have the requirement to talk to the outside world.
If you want to talk to other technologies, there can be some problems
- Interface builder (storyboards and xibs)
Excellent support for that. They work together almost as good as if they were designed for each other. - Obj-C
Excellent interoperation. I never found a feature of Obj-C that prevented me from using something from swift. On the other hand swift has a lot of features that don't have an equivalent in Obj-C so they cannot be used from the other side. - C
Obj-C interoperation with C is perfect, because it is built on top of it. Swift's is worse, because it's a completely different language. If you want to define a C struct, you have to do it in C. Some complex macros aren't imported into swift. You cannot get a stable address to a struct that is memory managed by swift, so you would have to put it on the heap. - C++
swift cannot talk to C++ officially yet, but swift for tensorflow people are working on it - asm
you cannot put inline asm in swift
2 Likes
Is Objective-C on average better for MacOS low level development than Swift?
Only in the regard that you have direct access to C. You could use the same C code in Swift with proper bridging.
One significant restriction is in-process plug-ins. Due to the way that Swift interacts with its runtime, you can’t build an in-process plug-in that supports systems prior to 10.14.4. A classic example of this is a macOS screen saver plug-in, but there are many others.
Share and Enjoy
Quinn “The Eskimo!” @ DTS @ Apple
2 Likes