How to open .SWIFT files on Mac

To open .SWIFT files on Mac, double-click the file if it is associated with Xcode, or right-click → Open With → Xcode.

Step-by-step instructions

  1. Double-click the file if it is associated with Xcode, or right-click → Open With → Xcode.
  2. If you just need to read/edit the code, open it in a text editor or another code editor (for example, Visual Studio Code).

Common issues

It opens as plain text without syntax highlighting or Swift features

Many editors can open .swift files, but not all have Swift language support enabled, so you may not get highlighting, autocomplete, or linting.

  1. Open the file in an IDE/editor known to support Swift (commonly Xcode; some users also use Visual Studio Code with Swift support).
  2. In your editor, ensure the language mode is set to Swift for the file.

You can read the file, but you cannot build or run it

A single .swift file is often only one part of a larger project; building typically requires the Swift toolchain and project/package configuration.

  1. Check whether the .swift file belongs to an Xcode project or Swift package and open the whole project, not just the file.
  2. Use the Swift.org documentation to set up the correct toolchain and build workflow for your platform.

The file opens in the wrong app when double-clicked

File association settings may point .swift to a generic editor or another app.

  1. On macOS, use right-click → Open With → Xcode (or your preferred editor) and optionally change the default association.
  2. On Windows/Linux, open your editor first and use File → Open to select the .swift file.

Security note

.swift files are plain text, but they can contain source code that—when compiled and run—may perform harmful actions. Treat .swift code from unknown sources like any untrusted program source.

Back to .SWIFT extension page