Swift Not Just for Apple: Cross-Platform Development in 2025

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

Swift Has Broken Out of the Apple Ecosystem

\n\n

For a long time, the Swift language was associated exclusively with iOS, macOS, and watchOS. If you wanted to write an app for Android or a web server, you reached for Java, Kotlin, or Python. But times have changed. Today, cross-platform development in Swift is not an enthusiast experiment, but a mature industry with core-level Linux support, official tools from Apple, and an active community.

\n\n

In this article, we'll explore how to write Swift for Windows, Linux, Android, and even the web. You'll see real code examples, learn about the Vapor and SwiftUI frameworks, and get a roadmap to get started. Let's go!

\n\n

Why Swift? Three Reasons to Go Beyond Apple

\n\n

1. Performance and Memory Safety

\n

Swift is a compiled language with Automatic Reference Counting (ARC). It delivers speed close to C++, while protecting against memory leaks and null-pointer errors at the compilation level. This is critical for server and desktop applications.

\n\n

2. Modern Syntax

\n

Protocols, extensions, generics, optional types — Swift has absorbed the best of functional and object-oriented programming. The code is concise and readable.

\n\n

3. Single Codebase

\n

By writing the logic once in Swift, you can run it on iOS, Android (via Swift Android Toolchain), Linux, Windows, and even in the browser (via WebAssembly). This reduces maintenance costs and speeds up time-to-market on new platforms.

\n\n

Toolkit for Cross-Platform Development in Swift

\n\n

Before writing code, let's look at what tools we'll need. Here is the main stack for cross-platform development in Swift in 2025:

\n\n
    \n
  • Swift Package Manager (SPM) — the standard package manager, works on all platforms.
  • \n
  • Vapor — the most popular web framework in Swift. Server logic, REST API, WebSockets.
  • \n
  • SwiftUI — a declarative UI framework. Works natively on macOS and iOS, on other platforms via SwiftUI-Web or Tokamak.
  • \n
  • Swift for TensorFlow / NumPy — machine learning and scientific computing.
  • \n
  • Android NDK + Swift Android Toolchain — compiling Swift code for Android.
  • \n
  • WebAssembly (WASI) — running Swift in the browser.
  • \n
\n\n

Writing a Server in Swift with Vapor (Linux / macOS / Windows)

\n\n

Let's start with the simplest and most useful thing — a web server. Vapor is a mature analog of Express.js or Flask, but in Swift. The code runs on Linux, macOS, and Windows (via Swift 6).

\n\n

Installing Vapor

\n
brew install vapor  # macOS\ncurl -sL https://apt.vapor.codes/install.sh | bash  # Linux\n# Windows: install Swift 6, then vapor via SPM
\n\n

Simple REST API with Vapor

\n

Let's create a project and write an endpoint for working with tasks (ToDo):

\n\n
// Sources/App/routes.swift\nimport Vapor\n\nfunc routes(_ app: Application) throws {\n    // GET /hello\n    app.get("hello") { req -> String in\n        return "Hello, cross-platform Swift!"\n    }\n\n    // GET /tasks\n    app.get("tasks") { req -> [String] in\n        return ["Learn Swift", "Write an article", "Run on Android"]\n    }\n\n    // POST /task\n    app.post("task") { req -> String in\n        let task = try req.content.decode(Task.self)\n        return "Task added: \\(task.title)"\n    }\n}\n\nstruct Task: Content {\n    let title: String\n    let isCompleted: Bool\n}
\n\n

Run the server with the command vapor run and open http://localhost:8080/hello. You will see a greeting. This same code works unchanged on Ubuntu, Windows Server, and macOS.

\n\n

Swift for Android: Writing a Native Library

\n\n

Many consider

Blogs

Book Recommendations