<!--
{
  "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/function()",
  "metadataVersion" : "0.1.0",
  "role" : "Macro",
  "symbol" : {
    "kind" : "Macro",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s8functionxycs26ExpressibleByStringLiteralRzlufm"
  },
  "title" : "function()"
}
-->

# function()

Produces the name of the declaration in which it appears.

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

## Overview

Inside a function,
the value `#function` produces is the name of that function,
inside a method it’s the name of that method,
inside a property getter or setter it’s the name of that property,
inside special members like `init` or `subscript`
it’s the name of that keyword,
and at the top level of a file it’s the name of the current module.

When used as the default value of a function or method parameter,
this macro’s value is determined
when the default value expression is evaluated at the call site.
For example:

```swift
func logFunctionName(string: String = #function) {
    print(string)
}
func myFunction() {
    logFunctionName() // Prints "myFunction()".
}
```

---

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)