<!--
{
  "documentType" : "article",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/macros",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "Macros"
}
-->

# Macros

Generate boilerplate code and perform other compile-time operations.

## Topics

### Essentials

  <doc://com.apple.Swift/documentation/Swift/applying-macros>

### Getting Source Location Information

[`file()`](/documentation/Swift/file())

Produces the path to the file in which it appears.

[`fileID()`](/documentation/Swift/fileID())

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

[`filePath()`](/documentation/Swift/filePath())

Produces the complete path to the file in which the macro appears.

[`function()`](/documentation/Swift/function())

Produces the name of the declaration in which it appears.

[`line()`](/documentation/Swift/line())

Produces the line number on which it appears.

[`column()`](/documentation/Swift/column())

Produces the column number in which the macro begins.

### Generating Compile-Time Diagnostics

[`warning(_:)`](/documentation/Swift/warning(_:))

Produces the given warning message during compilation.

[`error(_:)`](/documentation/Swift/error(_:))

Emits the given message as a fatal error
and terminates the compilation process.

### Writing Custom Macros

[`externalMacro(module:type:)`](/documentation/Swift/externalMacro(module:type:))

Specifies the module and type name for a macro’s implementation.

### Accessing the Dynamic Shared Object Handle

[`dsohandle()`](/documentation/Swift/dsohandle())

Produces the dynamic shared object (DSO) handle in use where the macro appears.



---

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)
