.swift File Extension
.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 type | Swift source code |
|---|---|
| MIME type | |
| Encoding | Unicode plain text, commonly UTF-8 |
| Operating systems | Windows, macOS, Linux |
| Opens with | Xcode, Visual Studio Code, Any text editor |
| Poly support | Yes. Poly recognizes .swift as readable Swift source code. |
| Indexed by Poly | Yes. Poly indexes readable source for exact and semantic search. |
| Preview in Poly | Yes. Swift source opens in Poly's code editor with syntax highlighting. |
| Poly agent | Yes. 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.
Working with .swift and related files
| File or path | Typical role |
|---|---|
Sources/App/main.swift | Conventional executable entry point in a package |
Sources/Library/Feature.swift | Library or application source |
Tests/LibraryTests/FeatureTests.swift | Test source |
Package.swift | Executable 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
- Swift Project. Declarations: Top-Level Code. Describes declarations and executable code allowed at the top level of Swift source files. ↩
- Apple. UTTypeSwiftSource. Identifies Swift source as
public.swift-sourceand as a source-code type. ↩ - Internet Assigned Numbers Authority. Media Types Registry. The registry contains no Swift-specific media type. ↩
- Apple. Editing Source Files in Xcode. Documents Xcode's source editor and Swift completion features. ↩
- Swift Project. Platform Support. Lists supported development toolchains and SourceKit-LSP availability for macOS, Linux distributions, and Windows. ↩ ↩2
- Swift Project. Creating a Swift Package. Shows conventional
SourcesandTestslayouts and theswift build,swift test, andswift runworkflows. ↩ - Apple. Get Started with Swift. Records Swift's 2014 WWDC announcement and original design goals. ↩
- Swift Project. Swift.org and Open Source. Records the December 3, 2015 open-source release. ↩