Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the win32 equivalent for mac?

The below link shows examples on how the Windows API works:

Module 1. Your First Windows Program

I am quite interested in how the Mac API looks like.

After doing some reading, I read a lot of things like XCode (Environment), Cocoa Framework, etc. However, I dont see any information about something like the Win32 API.

Doesn't Apple have a low level C API that is not based on Obective-C but just plain old C?

like image 579
Asperger Avatar asked Dec 02 '25 09:12

Asperger


1 Answers

Your link points to a tutorial for the GUI components of Windows. In that case, the equivalent for OS X is indeed the Cocoa framework, which consists of the Foundation and AppKit libraries, which are Objective-C libraries.

Cocoa's control drawing is entirely local to the application. Therefore, the only way to build applications using controls is with Objective-C. Nothing stops you from building a C API on top of that; similar tactics have been used to build libraries like Qt or bindings to languages like Python and Ruby.

There is no plain C GUI API in OS X. There are low-level APIs (part of the Quartz graphics framework, aka the Core Graphics API) for dealing with the window manager to open the top-level windows, but these are either very complicated or completely undocumented. And even then, you'd be responsible for doing all the controls and input handling yourself. Update Some of the basic facilities that applications build on top of are also available through C APIs, namely Core Foundation, Core Graphics, Core Text, and Grand Central Dispatch. But these are still not enough to use Cocoa; Cocoa is just built on top of them.

There is also the Carbon API, which is a C API, but was intended for transitioning pre-OS X applications to OS X and is thus not suitable for new application development. In fact, I'm not even sure it is even supported anymore.

So you have two options if you want to write a GUI program for OS X in plain C:

  • find a wrapper library
  • give up and learn Objective-C, which sits on top of plain C anyway

If online tutorials, including Apple's official ones, don't suit you, the Big Nerd Ranch books on Cocoa development are good. Note that their beginner-oriented books are transitioning to the Swift language, but they have a separate book dedicated to teaching Objective-C as well.

You'll also need to know that OS X applications almost exclusively design their user interfaces using a graphical designer called Interface Builder, akin to the form designers in Visual Studio. With the Windows API, you can still get away with doing things by code, and a lot of people do so; with OS X, doing everything programmatically is difficult (but still possible).

like image 58
andlabs Avatar answered Dec 04 '25 00:12

andlabs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!