Introduction to the Swift development

Apple programming language in Windows Introduction to the Swift development

To write Apps for macOS or iOS, recommended the development with Swift. Basically, the programming language is also available for Windows, offers here, but so many possibilities, such as macOS and Linux.

Company to the topic
Xcode on macOS, the default programming environment for Swift is that Windows will improve noticeably.
Xcode on macOS, the default programming environment for Swift is that Windows will improve noticeably.(Image: Joos / Apple)

Who developed the pogrammier language Swift, the ones that are not, actually, Linux or macOS. No wonder, the focus of Swift yet clear in the Apple world. Apple self-programmed, in the meantime, the largest part of its Apps with Swift.

Anyone who owns a Mac, the entry in Swift is expected to fall easier. For the development on an Apple operating system, it is the development environment (IDE) Xcode download and install. The Version 12 of Xcode offers the support of macOS 11.x (Big Sur), and bring Swift in Version 5.3.

As Apple explains in the Blog, to be Swift, even under Windows. Together with Visual Studio 2019 and Visual Studio Code, it is under the right conditions is easily possible to develop the Swift-Apps.

With Swift for Windows, the Compiler is available in Windows, But the Swift libraries in Windows to use. Also, Dispatch, Foundation, and XCTest can be used in Windows. With these libraries it is quite comprehensively is possible to develop applications for Windows.

This is useful, for example, for developers who want to keep it open, parallel to macOS or Windows to work. The possibilities of Swift for Windows with the calculator App on Github.

Visual Studio 2019 and Swift to prepare for the joint operation of

For the operation of Swift on Windows, first of all, the Windows will be downloaded-10-Toolchain for Swift. In addition, Visual Studio 2019 will be needed, at least as a free Community Edition on the computer. After the Installation of the necessary components for Visual Studio 2019, the Swift Toolchain for Windows can be installed.

For the development with Swift should be selected in the Visual Studio at the “Workloads” still “desktop development with C++” in the field “Desktop and mobile”. This setting can always catch up on. To do this, the Visual Studio will start in 2019 Installer and click the “Change” button. Options can be added, if Visual Studio is installed, for example, already on the Computer.

In “Individual components” can be achieved by Searching for the term “Windows” to filter the view. There should be two options, “C++Cmake Tools for Windows” and “Windows 10 SDK 10.0.18362.0” is selected. In addition, you should look for “Windows Universal C Runtime” and the corresponding component to install.

Now the Swift Toolchain for Windows can be installed. The “x64 Native Tools Command Prompt for VS2019 is needed” from the “Visual Studio 2019 program group. This Tool if you start from the right-click context menu with administrative Rights.

In addition, the following copy actions are meaningful, so that Swift can be used. Before the Copy, it should be checked in the Windows-Explorer, whether the directories votes. If you are upgrading from Visual Studio 2019 is also the version number of the directories change.

Copy %SDKROOT%usrshareucrt.modulemap "C:Program Files (x86)Windows Kits10Include10.0.18362.0ucrtmodule.modulemap"
Copy %SDKROOT%usrsharevisualc.modulemap "C:Program Files (x86)Microsoft Visual Studio2019CommunityVCToolsMSVC14.28.29333includevisualc.modulemap"
Copy %SDKROOT%usrsharevisualc.apinotes "C:Program Files (x86)Microsoft Visual Studio2019CommunityVCToolsMSVC14.28.29333includevisualc.apinotes"
Copy %SDKROOT%usrsharewinsdk.modulemap "C:Program Files (x86)Windows Kits10Include10.0.18362.0umwinsdk.modulemap"

Swift test

To test Swift in Windows, it will be sufficient, the Editor in Windows 10 (notepad.exe) a file with the name “ create the swift“. Ideally, it should be created on the hard disk of the computer, in the root directory of a folder in which Swift can be used.

For working with Swift, it may be advisable to use an Editor like Visual Studio Code. In the text file, the first Swift-test program can be stored as a Code, for example:

print("Hello, world")

The program can then be in the “x64 Native Tools Command Prompt for VS2019” tested. A further Variable is necessary, which is set with the following command:

set SWIFTFLAGS=-sdk %SDKROOT% -resource-dir %SDKROOT%usrlibswift -I %SDKROOT%usrlibswiftwindows

Also here the appropriate directories should be verified first. The Variable must be set each Time the x64 Native Tools Command Prompt for VS2019. Then, the written in Swift can be compiled program with the Swift Compiler:

Swiftc %SWIFTFLAGS -emit-executable -o hello.exe hello.swift

The Compiler is started in the x64 Native Tools Command Prompt from the directory where the source code for the Swift program.

Entry in Swift with macOS at the best

To begin with Swift in macOS, the easiest way out of the App Store in macOS, the development environment Xcode. to install. With Xcode programs for macOS and iOS can be developed. This is the default IDE for the development of Apple programs.

With Swift in Xcode, start, is created via the menu entry “FileNewProject” is a new team project in Swift. After that, it is necessary to create a new so-called “Playground”. Here’s the source code is entered, which is part of the created project. The Option to do this in Xcode by clicking on “FileNewPlayground” available.

When you Create the Playgrounds is already set, the Basis on which the program is developed. In the Playground in the Editor can, for example, by entering …

print("Hello, world")

… a line of text to be output. The execution starts by Clicking on the blue icon, or the Start of the program, in the lower area of Xcode.

Swift Tutorial-loading Playground

For a good introduction to the programming with Swift, it can be useful, the example Playground for developers to download and upload in Xcode with “FileOpen”. After that, the commands from the Tutorial in Xcode are available. The player characters in the lower area of the commands of the tutorial to be run.


Ready to see us in action:

More To Explore
Enable registration in settings - general
Have any project in mind?

Contact us: