Hence my question: Is it possible?
Hence my question: Is it possible?
Although I think it really depends on how you structure your program.
If you build your entire code around the ObjC object model and not just the parts that talk to operating system APIs you might see a performance hit since ObjC method calls are simply more expensive than a direct C function call (especially since C function calls can often be inlined)., and even setting or getting an ObjC object property involves a method call.
But since ObjC is also a complete C there's really no point in using more ObjC OOP features than really needed (e.g. just for talking to iOS/macOS framework APIs).
I think I had one objective C file in there for calling a library function I needed, but otherwise I just wrote C code.
SDL2 has input stuff built in, so that is easy.
I didn't need networking for my game, so I didn't have it, but networking is not particularly difficult to do cross platform (I'm assuming iOS lets you just use the "normal" sockets API?)
I also used SDL2 for the sound stuff, which was mostly playing back prerecorded things, but also a little bit of stuff synthesized on the fly.
But SDL3's has its own 3D API now which (I assume) wraps Metal on iOS.
One of the other answers also explains how to write a MacOS app using pure C.
So I think if UI stuffs can be written using C it then can build app using pure C.
The benefit of using C/C++ is that you are not writing 100% vendor locked code, only the HAL portion that interacts with some of Apple's Obj-C APIs will be platform-specific.
For example, if you write Linux-HAL then you can run your code, at least for testing, locally. And of course it opens the door to an Android port.
Separately, I'm wondering if anyone uses Kotlin Multiplatform and how well that works for iOS development.
As others have mentioned, for something like a simple game (rather than a normal GUI application), SDL offers a convenient wrapper that allows you to avoid touching anything Objective-C-related yourself, so you could write an entire app using only the SDL API, which is pure C. A nice bonus of that approach is that it would then work on other platforms with zero code changes.
Another source of C wrappers is Apple themselves, as iOS has a number of C interfaces like CoreFoundation that reduce how much Objective-C stuff you have to directly interact with, but there's nothing like that for UIKit, and every iOS app has to use UIKit at least a little.
While I don’t think that library does iOS specifically, you can have a look at the code to see how you can call objective-c from c. Spoiler: doing so kind of sucks, and also the library code isn’t the most elegant thing I’ve seen.
Not to mention you should probably opt for Swift first anyway, ObjC hasn’t been the default choice for quite some time now. ;P
Apart from the unfamiliar method call syntax it's actually a decent language extension once you understand what problems it wants to solve, and the killer feature of ObjC is that it doesn't mess with C semantics (which means ObjC part of the language is always automatically compatible with the latest C standard, while the 'C subset' of C++ is forever stuck in the mid-90s).
- https://github.com/garettbass/oc
- https://github.com/mitchellh/zig-objc
Whether that's better than writing ObjC directly is another question, think of ObjC as a convenient syntax sugar wrapper around macOS/iOS APIs which you only need in those parts of your application that talk directly to operating system APIs.
Also Apple is maintaining a C++ Metal API wrapper now (ok, technically that's not C): https://developer.apple.com/metal/cpp/
If you just want do to simple 'game-y stuff' (3D rendering, audio, low level touch input) you can also check out the Sokol headers (shameless plug): https://github.com/floooh/sokol, or I guess SDL will work too (especially with the new GPU API in SDL3) - at least the sokol header implementation code needs to be compiled as ObjC on macOS/iOS though (e.g. pass `-x objective-c` to Clang), since the macOS/iOS specific code paths are written in ObjC.
For the general case or when you need to access OS frameworks that are not wrapped by 3rd-party libraries:
If your app is mainly C code, have a thin layer of ObjC code that sits on top of the system ObjC APIs and which exposes a C API to the rest of the application.
Don't just tunnel every ObjC call through to C, instead wrap small feature blocks in ObjC and expose those features through a much simplified C API.
E.g. a hybrid C/ObjC application with only the necessary amount of ObjC code for talking to OS APIs, and all the 'business logic' in C (or another language, like C++, Zig or Rust).
C is Turing-complete, so you can technically write anything in it. But on iOS, you'd need to build your own C library for application-level Apple SDKs, since Apple doesn't provide one. For simple apps (like small games or toy utils) - a minimal wrapper in Objective-C or Swift could be just a few hundred lines.
You will notice that everyone that is replying that you can, also mentions that actually you have to make use from the Objective-C runtime from C.
So for all pratical purposes you will be writing an Objective-C application, manually writing the code that the Objective-C compiler used to generate when it was originally designed as a macro pre-processor generating C code at StepStone.
The way iOS is designed the bottom layer for userspace applications is Objective-C, not pure C UNIX style, and using the C APIs from the Objective-C runtime hardly changes that, you will be calling into the Objective-C runtime one way or the other.
Video games are the ones that do this by default. It would be close to impossible to have feature parity by coding a game for iOS in Swift, for Android in Java, for Steam in C++, etc. Unreal or Unity will have C/C++ code-bases with very light integration layers to do system calls.(The payment system may have code in Objective-C, for example, but mostly a wrapper for convenience reasons)
The other extreme is to just use webapps in an electron wrapper. But electron itself is build in C++.
My guess is that most developers are going to use the default Java/Swift combination for mobile development because that is what each company taught in their websites. I would prefer, thou, that engineers were more inclined to use opensource solutions to create common interfaces and avoid vendor lock-in. But cool events and free tutorials are hard to beat.
> Tauri requires various system dependencies for development on Linux. These may be different depending on your distribution ...
> WebView 2 is already installed on Windows 10 (from version 1803 onward) ...
> iOS development requires Xcode and is only available on macOS.
https://github.com/ColleagueRiley/RGFW.git
It was discussed recently around here: https://news.ycombinator.com/item?id=42217535
The macos backend is a neat hack, written in pure C.
You can create a frontend of whatever language you want for llvm so it’d translate it to llvm-ir.
You just need a small wrapper in objective c to make it work.
For some reason it required a bit of objective C for it to work with opengl.
I sold my macbook about 2 years later, around 2015.
I remember the feeling I first got (decades ago) when moving from C to objective C.
Having an xcodeproj was like the camel's nose under the tent, and then you couldn't go back. And you frequently had a big mess going forward when the next xcode version came out and it wouldn't work.
Suppafly•4d ago