.swift

What is a .swift file?

Swift Source File · Code and data · Apple · 2014

A .swift file is Swift source code, Apple's modern language for building iPhone, iPad, Mac and Apple Watch apps. It is a safe, fast language that replaced Objective-C for most Apple development.

Category
Code and data
MIME type
Type
Plain text
Is a .swift file safe to open? Caution. A .swift file is program source. Building and running it executes its code; review unfamiliar files first.

What is a .swift file used for?

Swift is designed to be safe and expressive, with strong typing and modern syntax. It is compiled by the Swift toolchain, usually inside Xcode, into native apps for Apple platforms, and also runs on Linux for server work.

App projects are built in Xcode, which turns .swift files into a runnable app. The source is plain text and opens in any editor.

What opens a .swift file?

The .swift format opens in the following apps, grouped by operating system. If one app does not work, try another from the same list.

Windows

  • VS Code (with Swift toolchain)
  • any text editor

macOS

  • Xcode
  • VS Code
  • any text editor

Linux

  • VS Code
  • vim
  • Swift toolchain

Open a .swift file step by step

  1. Confirm the file really is a .swift. Drop it into the WhatFileType identifier, which reads its signature in your browser without uploading anything.
  2. On Windows, open it with VS Code (with Swift toolchain) or any text editor.
  3. On Mac, use Xcode or VS Code.
  4. On Linux, try VS Code or vim.
  5. Still stuck? Convert the .swift to app (via Xcode), which opens more widely.

Why can't I open my .swift file?

Almost always because no installed app understands Swift. Install one of the apps above, or convert the file to a format your existing software already reads. If double-clicking opens the wrong program instead of nothing at all, the file association is set to the wrong app rather than the file being broken.

The other possibility is that the file is not really a .swift at all. Drop it into the file identifier to check it by its bytes instead of its name. Nothing is uploaded.

How to convert a .swift file

You can convert a .swift file to app (via Xcode) using a conversion tool or the export menu of an app that opens it.

Swift has no fixed magic number, so there is no signature table on this page. Its bytes alone do not prove the format: identification relies on the extension, the structure of the content and the program that created it. The magic-numbers reference lists the formats that do carry one.

Frequently asked questions

What is a .swift file?

A .swift file is Swift source code, Apple's modern language for building iPhone, iPad, Mac and Apple Watch apps. It is a safe, fast language that replaced Objective-C for most Apple development.

How do I run a .swift file?

On a Mac with Xcode, swift file.swift runs it as a script, or build an app in Xcode. The Swift toolchain also runs on Linux.

Do I need a Mac to write Swift?

For iPhone and Mac apps, effectively yes, because Xcode is Mac-only. Swift itself, for server or command-line code, also runs on Linux and Windows.

How do I open a .swift file?

Any text editor shows the source. Xcode on a Mac adds full building, debugging and app previews.

Related formats

Sources

Details on this page were checked against authoritative references. How sources are ranked and what is deliberately left out is set out in the methodology.