Building iOS apps with OCaml?

Hello,

Is it possible to create iOS apps with OCaml? I know it might take some extra work to use a foreign-function interface to call Objective-C functions to create the UI objects. But I’m wondering if I can cross compile for ARM and send a binary to my iPhone, and eventually the App Store. I’ll be working from macOS (x86).

I’m also interested in macOS apps for the App Store, which probably require cross-compiling to make an ARM+x86 binary of some kind.

Rob

3 Likes

Don’t know what the state of that is but at least it has been done at some point.

1 Like

Can confirm: I knew a guy who built a UI-intensive iOS app for iPhone and iPad, sold it on the store, for a good number of years. Don’t know if he does anymore, b/c lost touch with him after Nov 9 2016 (for obvious (political) reasons).

There’s always the path of hybrid apps.
You can compile to JavaScript and use a framework like CapacitorJS (or even the older Cordova).

This way you can also target android using the same codebase.

2 Likes

I’ve already seen people trying to do that. Here is an example.

It’s not from me but it’s an example I got shown when I built my OCaml editor for iOS/iPadOS/macOS.

1 Like

Couple more options …

Option 1: I mentioned last week in an unrelated thread that there is an opam package dkml-base-compiler that does cross-compilation. It supports most of the Android cross-compile matrix (ex. x86 → arm32), and the macOS (ex. x86_64 → arm64). I haven’t updated the official opam package to do iOS cross-compiles b/c most of my open-source time commitment has been for Windows. If you know how to compile the OCaml compiler, please extend that package! The bits will be very similar to the macOS cross-compiler, and I can guide you. See: https://discuss.ocaml.org/t/how-to-compile-ocaml-program-on-linux-for-running-on-freebsd/12110/4?u=jbeckford

Option 2: If you want a more out-of-the-box solution, you can use my commercial DkSDK native development kit. From an OCaml perspective, it is a OCaml-beginner friendly kit that embeds OCaml into other languages and frameworks. Two short-term things are relevant. 1) The docs mentions C a lot, but only because I haven’t finished writing its FFI. It will support OCaml objects ↔ Objective-C/Swift objects using Apple’s Foundation library. 2) I inadvertently broke support for Xcode builds, but that will get fixed sooner or later (depending on the interest).

Anyway, ping me privately if Objective-C/Swift dev in Xcode with the Run button automatically building FFI-supported OCaml code sounds like a fit.

1 Like

The Be Sport app is written in OCaml (iOS, Android, Web client and server) with Ocsigen (Eliom, Js_of_ocaml, Ocsigen Start…) as an HTML5 app (with Cordova)

1 Like

I also use Eliom for our internal mobile application and we are delighted. Very low maintenance, and only one application to write for all platforms. Very easy to use.

1 Like

Thanks everyone. This gives me a lot of stuff to research. I’m not sure what I’m doing yet.