Building Multiplatform apps

I wondered if with Swift something like Kotlin Multiplatform is possible as well.

So that all the core logic would be written in Swift and for the UI I would use the native stack of the platform itself. Currently I'm not planning to build an app that requires a version for Apple, Android, Linux, Windows, and web. But I'm curious if someone has already some experience in creating a monorepo for all that platform that is scalable and maintainable. How much effort would this take to make that possible?

1 Like

This is basically the approach that The Browser Company has taken and applied successfully for Arc and Dia. Both are extremely large projects and it has worked quite well.

1 Like

Take a look at @keeshux's blog series about doing that with CMake, including his OSS app with all the source.

2 Likes

This exists for Android (writing Swift, and running on Android)

3 Likes

Hi Roman!

I've been doing this for a while in a decently complex app, and I would say that the approach depends on several factors stemming from your app domain. To name a few:

  1. What's your "core logic" made of? As in, is the app more UI or logic?
  2. How does your data flow? Is it UI → Core (pull) or do you also need events/callback behavior like Core → UI (push)?
  3. How asynchronous do you want it to be?
  4. Is the Core platform-agnostic or very tied to the platform differences?
  5. Do you have non-Swift dependencies?
  6. Do you use SwiftPM or CMake?

I believe the answer to these questions could make the choice of sharing Swift logic a great bet or a lot of extra work. By that, I mean that in some cases, duplicating the native code could lead, paradoxically, to less maintenance than designing a shared core that fits heterogeneous platforms and programming languages.

1 Like

Ah true, is their browser closed source, right?

I would like to see an real world project repo how they set it up. Do you know any?

No, I don't think that there is anything that demonstrates that at the moment.

1 Like

Hey @compnerd , @Finagolfin , @mikaelacaron , @keeshux

Thank you very much for your replies.

I just recently saw this post which looks interesting: Bringing Goodnotes to the web with Swift and WebAssembly | Swift.org

But probably I had a wrong understanding about Swift + WASM. For me it would be nice if I could share "Core logic“ (network calls, data models, etc.) between all platforms and just have a different UI on every platform. But I think this isn't possible, right?

Did you read @keeshux's blog series that I linked you? I believe he is doing exactly that.

1 Like

That is exactly the model that I was mentioning upthread. The model that The Browser Company uses is precisely this: the core Arc/Dia logic is shared, and the UI layer is per platform (Windows using the Windows UI primitives and macOS using the macOS UI primitives).

1 Like

@Finagolfin , @compnerd

Yes true, I was more thinking of the networking + Codable and JSONDecoder /Encoder, if this will work on all platforms. Probably when I would use the Async HTTP Client it would work, right?

Currently I will start with a SwiftUI client + Vapor backend and Core library for sharing types, maybe later I will expand to more platforms based on demand. Would you recommend going for a mono or multi repo when starting out with the project?

Many core libraries work but there are API gaps on some platforms, and as for general Swift packages, you can check the index for platform compatibility. I have never built a full Swift GUI app, only command-line executables, so can't answer questions about repo organization and so on.

(post deleted by author)