Live data from Hacker News

Is it possible to write plain C iOS app in 2025?

news.ycombinator.com

11–20 of 74 posts

Re: Is it possible to write plain C iOS app in 2025?

#11
post #9

If you just want to write C and are ok linking to stuff that is in other languages, then I used SDL2 for my game which I wrote in C and is on the app store. It was a very pleasant experience, and if I were doing an iOS thing again, I would likely do something similar. I think I had one objective C file in there for calling a library function I needed, but otherwise I just wrote C code.

Just SDL2? Do you have access to OpenGL or some sound library as well? and if so what library are you using? How do you handle input and networking?

The game was 2d, and I just used the stuff in SDL_render.h for doing the graphics.

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.

Re: Is it possible to write plain C iOS app in 2025?

#13
Recently I have built a iOS network extension by porting fd.io vpp to Darwin platform, though the UI part is written by SwiftUI. But the core is written using good old C and dns component is written using rust with hickory library, I was considering using c-ares but wanna get a try with rust.

So I think if UI stuffs can be written using C it then can build app using pure C.

Re: Is it possible to write plain C iOS app in 2025?

#14
There is Objective-C++ (.mm extension), which I used extensively, where you have what is essentially a C/C++ implementation file, but you can use types and syntax from Objective-C, e.g. allowing you to call iOS APIs (UI, bluetooth, etc). Disk acccess can be done directly without objective C. Also network access. It is surprisingly unrestricted. This was a year or two ago. You need to get a path string to the app's Document folder through an Objective-C call though.

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.

Re: Is it possible to write plain C iOS app in 2025?

#15
post #5

Yes, it's basically writing a nibless objective-c application but manually translating all invocations to objc_msgsend yourself. You're not going to be able to avoid the objective-c runtime though.

Clang has a pretty cool flag to compile objc to c. I believe it exists for Apple to port their few apps to windows (eg iTunes), but I suspect it could be used to build a pure c environment as well.

Re: Is it possible to write plain C iOS app in 2025?

#18
Objective-C is designed in such a way that, generally speaking, anything you can do with Objective-C syntax can also be done with a simple C function call to one of the Objective-C runtime functions. So you can write an entire iOS app in pure C. However, the Objective-C stuff is a lot more pleasant to use if you use the syntax for it.

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.

Re: Is it possible to write plain C iOS app in 2025?

#19
post #15
post #5

Yes, it's basically writing a nibless objective-c application but manually translating all invocations to objc_msgsend yourself. You're not going to be able to avoid the objective-c runtime though.

Clang has a pretty cool flag to compile objc to c. I believe it exists for Apple to port their few apps to windows (eg iTunes), but I suspect it could be used to build a pure c environment as well.

That is very cool, I think it's `-rewrite-objc`. Presumably it still needs to be linked to the objc runtime. It says it lowers to C++ instead of C though, now I wonder what pieces cannot be implemented using pure c.

Re: Is it possible to write plain C iOS app in 2025?

#20
post #14

There is Objective-C++ (.mm extension), which I used extensively, where you have what is essentially a C/C++ implementation file, but you can use types and syntax from Objective-C, e.g. allowing you to call iOS APIs (UI, bluetooth, etc). Disk acccess can be done directly without objective C. Also network access. It is surprisingly unrestricted. This was a year or two ago. You need to get a path string to the app's Do…

If you just need C instead of C++ then .m suffices, ojective-c is a strict superset of C.
Post reply on HN