can IOS load 3rd party C/C++ code?

By Pax, 13 September, 2024

Forum
App Development and Programming

hello.
I am learning C and C++
can IOS somehow support that?

Options

Comments

By robin24 on Sunday, September 15, 2024 - 21:45

Hi,

Whether you'll be able to use C / C++ for iOS software development depends on what you're trying to accomplish.
If you're hoping to build apps entirely using C++ and then run them on your iOS device, that's unfortunately not going to work.
The main programming language for iOS, as well as all other Apple platforms is Swift, which I'd also personally recommend learning if app development is something you'd like to pursue.
Now, what actually does work is accessing C / C++ code from Swift. So, if you are developing a Swift app and would like to access a library written in C / C++, that's something which you should absolutely be able to do.
I found this article which can hopefully help you get started:
https://www.swift.org/documentation/articles/wrapping-c-cpp-library-in-swift.html

Cheers,
Robin

By João Santos on Sunday, September 15, 2024 - 21:45

It's perfectly possible to run C or C++ code on iOS, both by linking to it or by directly adding C and C++ source files to the project, however most public Apple frameworks are written in Objective-C, and some are pure Swift, so they need to be called from Objective-C, Objective-C++, or Swift code. This includes the main loop handled by UIApplication, which handles the display server connection without which you cannot display anything to the screen or receive any kind of event from the system. Also, console output will not be displayed on the device, but you can still read it in Xcode or in the Console application on MacOS. Finally, while there are probably a few libraries that you can use to write the front-end in C or C++, I'm not going to recommend any since I only have native experience and the likelihood of those libraries having accessibility issues or missing functionality is pretty high.

Assuming that you are totally blind like me and most people around here, I recommend learning Swift and SwiftUI. Swift is the language in which pretty much all modern native iOS code is written in, and SwiftUI is a relatively new declarative and reactive UI designing framework by Apple which, as a result of being code-first, is also very accessible. While SwiftUI does not support everything UIKit and its derivate frameworks do, having the ability to design the layout using a declarative and reactive paradigm and relegate UIKit to specific unsupported controls helps a lot. Swift is also memory safe, and provides a structured concurrency model that, if used, also eliminates pretty much all concurrency problems.