.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.

How to open 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. For a step-by-step walkthrough, see how to open a .swift file.

Windows

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

macOS

  • Xcode
  • VS Code
  • any text editor

Linux

  • VS Code
  • vim
  • Swift toolchain

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 file signature (magic bytes)

Programs recognise a .swift file by the bytes at the start of the file, not by its name. These are the signatures for Swift.

Hex signatureOffsetNote
(no fixed signature)0plain text; no fixed magic bytes

See the full magic-numbers reference for every format.

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: