.swift File Extension

Learn what a .swift file contains, how to open and build Swift source code, how Poly supports it, and which related project files matter.

File extension details for .swift

Full Support
File typeSwift source code
MIME type
EncodingUnicode plain text, commonly UTF-8
Operating systemsWindows, macOS, Linux
Opens withXcode, Visual Studio Code, Any text editor
Poly supportYes. Poly recognizes .swift as readable Swift source code.
Indexed by PolyYes. Poly indexes readable source for exact and semantic search.
Preview in PolyYes. Swift source opens in Poly's code editor with syntax highlighting.
Poly agentYes. The Poly agent can read and reason about the source text.

What kind of file is a .swift?

A .swift file contains source code written in the Swift programming language. It is editable Unicode text, not a compiled application. A file can contain imports, declarations, expressions, and statements. Swift also permits executable top-level code in a program's entry-point file.1

Swift source has no fixed magic bytes. Software normally identifies it from the .swift suffix, project context, and recognizable syntax. Apple assigns Swift source the Uniform Type Identifier public.swift-source, but IANA does not register a Swift-specific media type.23 Poly treats the extension as readable text/plain.

Package.swift is a Swift source file with a special role: it describes a Swift package. Renaming unrelated text to .swift does not translate it into Swift or prove that it will compile.

How do I open a .swift on my computer?

Any text editor can open .swift files on Windows, macOS, or Linux. Xcode provides Swift editing, completion, navigation, debugging, and build tools on macOS. Visual Studio Code with the Swift extension is a cross-platform option, and editors that support the Language Server Protocol can use SourceKit-LSP.45

For a Swift package, open the folder containing Package.swift, then use the installed Swift toolchain:

swift build
swift test
swift run

Swift Package Manager conventionally places production source under Sources/<TargetName>/ and tests under Tests/<TargetName>Tests/.6 Opening a source file as text does not execute it. Building or testing an unfamiliar package can download dependencies and run code, so review it first and use an isolated environment when trust is uncertain.

Poly support for .swift

Poly opens .swift files in a code-friendly viewer with Swift syntax highlighting, word wrap, and in-file search. It indexes readable source for exact and semantic search, so you can find a type by name or search for code by its likely purpose. The Poly agent can summarize a file, explain a function, and help trace behavior through the source you provide.

Poly does not compile or execute Swift, resolve packages, download dependencies, or recreate Xcode's complete project model. Keep related source, tests, Package.swift, and project documentation together when repository-level context matters.

History of .swift

Apple developed Swift and announced it at WWDC in 2014 as a safe, approachable, high-performance general-purpose language.7 The .swift suffix became its standard source-file convention. On December 3, 2015, Apple published the language, supporting libraries, debugger, and package manager as open source.8

The same suffix now appears well beyond Apple app projects. Official Swift toolchains support development on macOS, several Linux distributions, and Windows.5 The filename does not identify the Swift language mode, deployment target, or required toolchain version. Build settings and package configuration supply those details.

File or pathTypical role
Sources/App/main.swiftConventional executable entry point in a package
Sources/Library/Feature.swiftLibrary or application source
Tests/LibraryTests/FeatureTests.swiftTest source
Package.swiftExecutable Swift package manifest
.build/Generated Swift Package Manager output

Keep .swift files, the package manifest, tests, and any checked-in dependency lockfile in version control. Build products are separate artifacts for a particular platform and configuration. Changing an executable, library, or object file's extension to .swift cannot recover its original source, comments, or formatting.

Footnotes

  1. Swift Project. Declarations: Top-Level Code. Describes declarations and executable code allowed at the top level of Swift source files.
  2. Apple. UTTypeSwiftSource. Identifies Swift source as public.swift-source and as a source-code type.
  3. Internet Assigned Numbers Authority. Media Types Registry. The registry contains no Swift-specific media type.
  4. Apple. Editing Source Files in Xcode. Documents Xcode's source editor and Swift completion features.
  5. Swift Project. Platform Support. Lists supported development toolchains and SourceKit-LSP availability for macOS, Linux distributions, and Windows. 2
  6. Swift Project. Creating a Swift Package. Shows conventional Sources and Tests layouts and the swift build, swift test, and swift run workflows.
  7. Apple. Get Started with Swift. Records Swift's 2014 WWDC announcement and original design goals.
  8. Swift Project. Swift.org and Open Source. Records the December 3, 2015 open-source release.
© Poly Corp. 2026