edg5000 2 days ago

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.

2
anon6362 2 days ago

Objective-C is a C superset, while Objective-C++ is a C++ superset, where C++ is a mostly C superset. You're not really buying anything using Objective-C++ by adding another form of OOP, except perhaps for interop with C++.

iainmerrick 2 days ago

It’s the interop that’s a big deal. The platform is Obj-C (or was, now it’s Swift), most useful non-iOS-specific libraries are C/C++, being able to use Obj-C++ to glue everything together is really convenient. Vastly easier than e.g. JNI on Android.

anon6362 1 day ago

There it is. True, it's very painful to wrap C++ code into C libraries (or requiring C calling conventions) where C++ isn't allowed.

Separately, I'm wondering if anyone uses Kotlin Multiplatform and how well that works for iOS development.

krackers 2 days ago

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

larusso 2 days ago

It‘s a superset of ANSI-C. One needs to be carful to mention this. I‘m not aware that this had changed and also added some small grieve back in the days for me. But I sadly can‘t remember anymore what didn‘t work for me.

krackers 1 day ago

I'd be curious if you can remember what differences there were. It's compatible with all C99 and C11 syntax I've tried

larusso 15 hours ago

I think it was specifically in .m files. Obj-c is using ANSI-C (c89) which lacks certain features and keywords. Mixing with c99 files is of course possible. Maybe that was also an issue in older versions of clang.

krackers 14 hours ago

I haven't run into such issues intermingling C11 features in a .m file. Possibly you just needed to set the right compiler flags, or it was a bug in older versions of clang.

larusso 11 hours ago

Could be. My obj-c days are long over though. The time I worked with was between 2009 and 2015.