---
title: "init(_:strategy:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/url/init(_:strategy:)"
---

# init(_:strategy:)

Creates a URL instance by parsing the provided input in accordance with a parse strategy.

## Declaration

```swift
init<T>(_ value: T.ParseInput, strategy: T) throws where T : ParseStrategy, T.ParseOutput == URL
```

## Parameters

- `value`: The value to parse, as the input type accepted by strategy. For doc://com.apple.foundation/documentation/Foundation/URL/ParseStrategy, this is doc://com.apple.documentation/documentation/Swift/String.
- `strategy`: A parse strategy to apply when parsing value.

## Discussion

Discussion The following example parses a URL string, with a custom strategy that provides a default value for the port component if the source string doesn’t specify one. let urlString = "https://internal.example.com/path/to/endpoint?key=value" let url = try? URL(urlString, strategy: .url     .port(.defaultValue(8080))) // https://internal.example.com:8080/path/to/endpoint?key=value

## See Also

### Creating a URL by parsing

- [URL.ParseStrategy](foundation/url/parsestrategy.md)
