<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/URL/formatted()",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation3URLV9formattedSSyF"
  },
  "title" : "formatted()"
}
-->

# formatted()

Formats the URL using a default format style.

```
func formatted() -> String
```

## Return Value

A string representation of the URL, formatted according to the default format style.

## Discussion

Use this method to create a string representation of a URL using the default [`URL.FormatStyle`](/documentation/Foundation/URL/FormatStyle) configuration. As seen in the following example, the default style creates a string with the scheme, host, and path, but not the port or query.

```swift
let url = URL(string:"https://www.example.com:8080/path/to/endpoint?key=value")!
let formatted = url.formatted() // "https://www.example.com/path/to/endpoint"
```

To customize formatting of the URL, use [`formatted(_:)`](/documentation/Foundation/URL/formatted(_:)), passing in a customized [`URL.FormatStyle`](/documentation/Foundation/URL/FormatStyle).

---

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)