<!--
{
  "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/FormatStyle/format(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation3URLV11FormatStyleV6formatySSACF"
  },
  "title" : "format(_:)"
}
-->

# format(_:)

Formats a URL, using this style.

```
func format(_ value: URL) -> String
```

## Parameters

`value`

The URL to format.

## Return Value

A string representation of `value`, formatted according to the style’s configuration.

## Discussion

Use this method when you want to create a single style instance, and then use it to format multiple URL instances. The following example creates a custom format style and then uses it to format a variety of URLs in an array:

```swift
let style = URL.FormatStyle(
    scheme: .never,
    user: .never,
    password: .never,
    host: .omitSpecificSubdomains(["www", "mobile", "m."],
                                  includeMultiLevelSubdomains: true),
    port: .never,
    path: .always,
    query: .never,
    fragment: .never)
let urls = [
    URL(string: "https://www.example.com/path/one")!,
    URL(string: "https://beta.example.com/path/two")!,
    URL(string: "https://beta.staging.west.example.com/three")!,
    URL(string: "https://query.example.com/four?key4=value4")!
]
let formatted = urls.map { $0.formatted(style) } // ["example.com/path/one", "beta.example.com/path/two", "west.example.com/three", "query.example.com/four"]
```

To format a single floating-point value, use the [`URL`](/documentation/Foundation/URL) instance method [`formatted(_:)`](/documentation/Foundation/URL/formatted(_:)) method passing in an instance of [`URL.FormatStyle`](/documentation/Foundation/URL/FormatStyle), or [`formatted()`](/documentation/Foundation/URL/formatted()) to use a default style.

---

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)