<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: 26.0.0 -",
    "macOS: 26.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 26.0.0 -",
    "watchOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/URL/init(template:variables:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation3URLV8template9variablesACSgAC8TemplateV_SDyAH12VariableNameVAH5ValueVGtcfc"
  },
  "title" : "init(template:variables:)"
}
-->

# init(template:variables:)

Creates a new `URL` by expanding the RFC 6570 template and variables.

```
init?(template: URL.Template, variables: [URL.Template.VariableName : URL.Template.Value])
```

## Parameters

`template`

The RFC 6570 template to be expanded.

`variables`

Variables to expand in the template.

## Discussion

This will fail if variable expansion does not produce a valid,
well-formed URL.

All text will be converted to NFC (Unicode Normalization Form C) and UTF-8
before being percent-encoded if needed.

---

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)