Swift Has Broken Out of the Apple Ecosystem
\n\nFor 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\nIn 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\nWhy Swift? Three Reasons to Go Beyond Apple
\n\n1. Performance and Memory Safety
\nSwift 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\n2. Modern Syntax
\nProtocols, extensions, generics, optional types — Swift has absorbed the best of functional and object-oriented programming. The code is concise and readable.
\n\n3. Single Codebase
\nBy 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\nToolkit for Cross-Platform Development in Swift
\n\nBefore 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-WeborTokamak. \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
Writing a Server in Swift with Vapor (Linux / macOS / Windows)
\n\nLet'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\nInstalling Vapor
\nbrew install vapor # macOS\ncurl -sL https://apt.vapor.codes/install.sh | bash # Linux\n# Windows: install Swift 6, then vapor via SPM\n\nSimple REST API with Vapor
\nLet'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\nRun 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.
Swift for Android: Writing a Native Library
\n\nMany consider