<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/fileID()",
  "metadataVersion" : "0.1.0",
  "role" : "Macro",
  "symbol" : {
    "kind" : "Macro",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s6fileIDxycs26ExpressibleByStringLiteralRzlufm"
  },
  "title" : "fileID()"
}
-->

# fileID()

Produces a unique identifier for the source file in which the macro appears.

```
@freestanding(expression) macro fileID<T>() -> T where T : ExpressibleByStringLiteral
```

## Overview

The unique identifier has the form *module*/*file*,
where *file* is the name of the file in which the expression appears
and *module* is the name of the module that this file is part of.

Because `#fileID` doesn’t embed the full path to the source file,
unlike `#filePath`,
it gives you better privacy and reduces the size of the compiled binary.

Note: To parse a `#fileID` expression,
read the module name as the text before the first slash (`/`)
and the filename as the text after the last slash.
In future versions of Swift,
the string might contain multiple slashes,
such as `MyModule/some/disambiguation/MyFile.swift`.

This macro’s value can be changed by `#sourceLocation`,
as described in [Line Control Statement](https://docs.swift.org/swift-book/documentation/the-swift-programming-language/statements#Line-Control-Statement) in [The Swift Programming Language](https://docs.swift.org/swift-book/).

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)