<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 8.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/URLComponents/init(url:resolvingAgainstBaseURL:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation13URLComponentsV3url23resolvingAgainstBaseURLACSgAA0G0Vh_Sbtcfc"
  },
  "title" : "init(url:resolvingAgainstBaseURL:)"
}
-->

# init(url:resolvingAgainstBaseURL:)

Creates a URL components instance from a URL string, optionally resolving against a base URL.

```
init?(url: URL, resolvingAgainstBaseURL resolve: Bool)
```

## Parameters

`url`

The URL string to parse.

`resolve`

Controls whether the initializer resolves the URL against its base URL before parsing. If `url` is a relative URL, setting `resolve` to `true` creates components using the [`absoluteURL`](/documentation/Foundation/URL/absoluteURL) property.

## Discussion

---

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)