Develop Swift iOS apps on Windows
Open an Xcode project and build, with SPM dependencies resolved automatically. Pure Swift packages can be converted to an app to produce an .ipa.
Build Swift iOS projects on Windows, install them on your iPhone and debug with breakpoints. SwiftUI, Swift Package Manager and mixed Swift and Objective-C are all supported. KXBuild reads build settings, target dependencies and compiler flags by Xcode's rules, so your project works as is. Swift projects come in two kinds, Xcode projects and standalone Swift packages with only a Package.swift. Each is covered below. For projects that use CocoaPods, see CocoaPods.
Xcode projects
A project with an .xcodeproj or .xcworkspace. Dependencies can be Swift packages, which are resolved automatically before each build.
Create a project
To use an existing project, open its folder in VS Code with File > Open Folder…, or drag the folder into VS Code. Otherwise, create one.
Use either of these
-
VS Code extension
Run KXBuild: New Project from the Command Palette and pick the "iOS App (SwiftUI)" or "iOS App (Swift, UIKit)" template.
-
Command line
> kxbuild project create -t app_swiftui -n MyApp -o D:\projects
Run doctor
Doctor checks your build environment and fixes anything missing.
Use either of these
-
VS Code extension
In the title bar of the KXBuild view, open the ··· menu and run Doctor (fix environment).
-
Command line
> kxbuild doctor .\MyApp.xcodeproj
Add a Swift package dependency
This is the equivalent of Add Package Dependencies in Xcode. As in Xcode, a remote package defaults to its latest version and allows updates up to the next major version, and adding one needs a network connection.
Use either of these
-
VS Code extension
Run KXBuild: Add Swift Package Dependency… from the Command Palette, or right-click a target in the KXBuild view and choose it there. Enter the package's Git URL or pick a local package folder, then choose the products you need.
-
Command line
Run the command for where the package lives.
Remote package
> kxbuild project add-package -P .\MyApp.xcodeproj --url https://github.com/Alamofire/Alamofire.git --product AlamofireLocal package
> kxbuild project add-package -P .\MyApp.xcodeproj --path ..\MyKitTo set a version or target, see project add-package.
Write code
Open a .swift file and you get completion, go to definition and error checking, including for SwiftUI and system framework APIs. Build once before you import modules from other targets or Swift packages in the project. If completion misbehaves, see Code completion and indexing.
Debug
Connect your iPhone over USB, select it in the KXBuild view and press F5. KXBuild builds, installs and stops at your breakpoints. Breakpoints work in both Swift and Objective-C code.
Release
Build with the Release configuration to get build\MyApp.ipa in the project folder. To upload it to App Store Connect, see Release and App Store submission.
Use either of these
-
VS Code extension
Switch the configuration to Release in the Build configuration node of the KXBuild view, then run KXBuild: Build from the Command Palette.
-
Command line
Run the command for your project type.
.xcodeproj project
> kxbuild build .\MyApp.xcodeproj -c Release.xcworkspace workspace
> kxbuild build .\MyApp.xcworkspace -c Release
Standalone Swift packages
For a project with only a Package.swift and no Xcode project, open the folder containing Package.swift in VS Code to write and compile-check code. A Swift package can't be packaged as an app on its own, and that's true on a Mac too. To install it on an iPhone or produce an .ipa, find your case below.
- The package is an app. Its executable target holds a SwiftUI or UIKit app entry point. Follow the steps below to convert it to an app project.
- The package only provides libraries for apps to use. In the app project, add it as a Swift package dependency as in step 3 above.
Write code and compile-check
Open a .swift file and you get completion, go to definition and error checking, including for SwiftUI, UIKit and other iOS framework APIs. To compile-check, run this in the folder containing Package.swift.
> kxbuild build .Convert to an app project
Converting adds a MyApp subfolder to the package folder with the app project inside. The app still uses the package's code, so when you edit the package, you edit the app. Commit this subfolder to version control along with the package.
If the app uses a target from the same package that has no matching library product, the conversion adds a .library entry to products in Package.swift. After converting, review and commit that change to Package.swift.
Use either of these
-
VS Code extension
Run KXBuild: Convert Swift Package to App Project from the Command Palette (or click the package's row in the KXBuild view), then enter the app name and bundle ID. The new project becomes the startup project.
-
Command line
Run this in the folder containing Package.swift.
> kxbuild project spm2app . -n MyApp -b com.example.myapp
Debug and release
In the KXBuild view, switch the startup project to MyApp. From there, follow the debug and release steps for Xcode projects above. The .ipa is written to MyApp\build\MyApp.ipa. On the command line, build this project.
> kxbuild build .\MyApp\MyApp.xcodeproj -c ReleaseTroubleshooting
| Symptom | Fix |
|---|---|
| A Debug build fails to link with undefined symbol: …vpfi | A known issue in the open-source Swift compiler. It happens with a property that has an initial value, such as @State private var count = 0, when the struct's init is in another file. Set the environment variable KXBUILD_SWIFT_WHOLE_MODULE=all, reopen VS Code and build again. Swift targets are then built as a whole module. See Troubleshooting. |
Next steps
Build and configure
Debug versus Release, choosing a scheme, target and configuration, overriding build settings, where build products go, when you get an .ipa and when Swift package dependencies resolve.
Release and App Store submission
Build Release with a Distribution certificate to get an .ipa, upload it to App Store Connect with Transporter or Appuploader, then go through TestFlight and App Review. Ad Hoc and enterprise distribution work the same way.
Don't see your framework?
kxbuild is a general-purpose build toolchain, so if your framework produces an Xcode project, KXBuild can build it. The list above covers common cases only. Tell us about your setup.