0

My relations with Objective-C and XCode are perfectly summarized as «hate from the first sight». Emotional as it is, I`d still like to develop GUI apps in C, the way I`m used to (.C files, .H files, Makefile and Clang), even for MacOS X ≥ 10.8.

I know that long ago there was Carbon, but now it`s of no use. CoreFoundation is good, especially in cases where the so-called toll-free bridging to NS* classes is available, but it`s only a scarce subset of what Cocoa has.

The question is: are there any ready to use C bindings to Cocoa?

I`ve almost succeeded in writing these myself, even with a makeshift subclass factory to support delegating, but then a thought stroke me: I`m definitely not the first one. However, all that I could google out was this and this.

Community
  • 1
  • 1
hidefromkgb
  • 5,834
  • 1
  • 13
  • 44
  • 5
    IMO: even if you don't like it, get used to Objective-C or Swift, if you want to program for the macOS. Yes, you can write your own C bindings, but it would soon get very tedious. – Rudy Velthuis Oct 16 '16 at 14:25
  • 3
    Related: [How to write an iOS app purely in C?](http://stackoverflow.com/q/10289890) – jscs Oct 16 '16 at 17:34
  • You could always install X11. – bbum Oct 16 '16 at 23:04
  • @bbum, I may be wrong, but I doubt that X11 apps are native for OS X. – hidefromkgb Oct 16 '16 at 23:37
  • 2
    Yeah-- but you're asking for a non-native way to develop apps for OS X. If you want to use Cocoa, you're going to have to deal with an OO interface to the system and you'll need to consume either Swift or ObjC APIs. Unavoidable unless you use a non-native interface. X11 is one of the few that would truly be a GUI programming environment that works on OS X that doesn't use Cocoa directly or indirectly (mostly-- there is still some exposure). – bbum Oct 17 '16 at 00:54
  • @bbum, the problem of dealing with basic interfaces like, say, delegation or superclass access is already solved. I have a bare-bones implementation in C right now. The very problem is the sheer amount of functions I\`ll have to define to make it a usable binding. – hidefromkgb Oct 17 '16 at 03:03
  • @bbum: posted my own solution, just in case. – hidefromkgb Feb 25 '17 at 20:30
  • A nice bit of academic adventure! Still, what @RudyVelthuis said above pertains. As you note, the end result is incomplete (and keep in mind that OS X is *much* more than just the AppKit and Foundation) and subject breakage with every new release of OS X. Is it really worth the effort in a production context? – bbum Feb 26 '17 at 18:47

1 Answers1

0

…okay.

After much struggle, I`ve finally come up with a usable solution, even though it`s nowhere near complete.

https://github.com/hidefromkgb/mac_load

This is a header-only Cocoa C binding. The main drawbacks are:

  1. it covers much less than 1% of all Cocoa API;
  2. its own helper functions are, for now, subject to rapid change;
  3. it`s still undocumented.

Anyway, it does help write Cocoa code in readable C — a tiny subset of what`s actually possible with Cocoa, but now the measure of this subset only depends on function coverage.

Here`s an example of what it can do:

https://github.com/hidefromkgb/msu3-waves/tree/master/macos

P.S.: don`t trust GitHub language analyzer, there`s not a single line of ObjC-specific code here.

hidefromkgb
  • 5,834
  • 1
  • 13
  • 44